This document was uploaded by user and they confirmed that they have the permission to share
it. If you are author or own the copyright of this book, please report to us by using this DMCA
report form. Report DMCA
I have just created a vector \verb@V01@ with all the integers from 1 to 100! But now you didn't see it. I typed \begin{tabbing} firstDemo.Rnw
2009-01-06
\documentclass{article} \usepackage{amsmath} \usepackage{amscd} \usepackage[tableposition=top]{caption} \usepackage{ifthen} \usepackage[utf8]{inputenc} \begin{document} \title{A very simple Sweave Demo} \author{Karsten D. Wolf} \maketitle \section {Introduction} As you can read on my World of R-Craft blog (worldofrcraft.blogspot.com/), it is rather easy to setup your Mac to be a reproducible research workstation. Just mix and match the power of R and \LaTeX. Right now I am still a bit rusty on my \LaTeX side of things, but I will definitely improve on that over the course of the next months. \section {First examples} Now, let's do a quick example <<exampleOne>>= 2 * 1024 @ What I actually typed in \[email protected]@ was \begin{tabbing} \verb@<<exampleOne>>=@ \\ \verb@2 * 1024@ \\ \verb+@+ \\ \end{tabbing} As you can see (or at least, suspect): this is not \LaTeX. It is a so called ``code chunk'' to be processed by \verb@Sweave@. \verb@Sweave@ processes all the R code chunks and stuffs the output in the \LaTeX\ file it is creating. That is all very well, but you can also do some R processing, hide the most of it and then - bang! - show some of it. That is very convenient if you are doing longer analysis and just want to show that table with all of the results. Now let's do this! Right here! <<exampleTwo, echo=FALSE, include=FALSE>>= v01 <- c(1:100) @ I have just created a vector \verb@V01@ with all the integers from 1 to 100! But now you didn't see it. I typed \begin{tabbing} - 1/3 -
firstDemo.Rnw
2009-01-06
\verb@<<exampleTwo, echo=FALSE, include=FALSE>>=@ \\ \verb@v01 <- c(1:100)@ \\ \verb+@+ \\ \end{tabbing} The \verb@echo=FALSE, include=FALSE@ does the trick. \verb@Echo=FALSE@ means no display of my input. \verb@Include=FALSE@ means no display of output. Nada! Later I can use the results of my code, because all of the R code in my document is run in one session: <<exampleTwo>>= length(v01) @ \section {Examples with graphics} Text is all and well, but we want to see graphics in our documents. Let's create some data we can plot: <>= # code from http://addictedtor.free.fr/graphiques/graphcode.php?graph=7 par(bg="white") n <- 100 set.seed(43214) #just so we have the same exact graph x <- c(0,cumsum(rnorm(n))) y <- c(0,cumsum(rnorm(n))) xx <- c(0:n, n:0) yy <- c(x, rev(y)) @ Figure~\ref{fig:one} (p.~\pageref{fig:one}) is produced by the following code <