Você está na página 1de 2

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 firstDemo.Rnw 2009-01-06


\documentclass{article} \verb@<<exampleTwo, echo=FALSE, include=FALSE>>=@ \\
\verb@v01 <- c(1:100)@ \\
\usepackage{amsmath} \verb+@+ \\
\usepackage{amscd} \end{tabbing}
\usepackage[tableposition=top]{caption} The \verb@echo=FALSE, include=FALSE@ does the trick. \verb@Echo=FALSE@ means
\usepackage{ifthen} no display of my input. \verb@Include=FALSE@ means no display of output.
\usepackage[utf8]{inputenc} Nada! Later I can use the results of my code, because all of the R code in my
document is run in one session:
\begin{document} <<exampleTwo>>=
length(v01)
\title{A very simple Sweave Demo} @
\author{Karsten D. Wolf} \section {Examples with graphics}
\maketitle Text is all and well, but we want to see graphics in our documents. Let's
create some data we can plot:
\section {Introduction} <<plot>>=
As you can read on my World of R-Craft blog (worldofrcraft.blogspot.com/), it # code from http://addictedtor.free.fr/graphiques/graphcode.php?graph=7
is rather easy to setup your Mac to be a reproducible research workstation. par(bg="white")
Just mix and match the power of R and \LaTeX. Right now I am still a bit n <- 100
rusty on my \LaTeX side of things, but I will definitely improve on that over set.seed(43214) #just so we have the same exact graph
the course of the next months. x <- c(0,cumsum(rnorm(n)))
y <- c(0,cumsum(rnorm(n)))
\section {First examples} xx <- c(0:n, n:0)
Now, let's do a quick example yy <- c(x, rev(y))
<<exampleOne>>= @
2 * 1024
@ Figure~\ref{fig:one} (p.~\pageref{fig:one})
What I actually typed in \verb@firstDemo.Rnw@ was is produced by the following code
\begin{tabbing} <<label=fig1plot,include=FALSE>>=
\verb@<<exampleOne>>=@ \\ plot(xx, yy, type="n", xlab="Time", ylab="Distance")
\verb@2 * 1024@ \\ polygon(xx, yy, col="gray")
\verb+@+ \\ title("Distance Between Brownian Motions")
\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@. \begin{figure}
\verb@Sweave@ processes all the R code chunks and stuffs the output in the \begin{center}
\LaTeX\ file it is <<label=fig1,fig=TRUE,echo=FALSE>>=
creating. That is all very well, but you can also do some R processing, hide <<fig1plot>>
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 \end{center}
the results. Now let's do this! Right here! \caption{Distance between brownian motions}
<<exampleTwo, echo=FALSE, include=FALSE>>= \label{fig:one}
v01 <- c(1:100) \end{figure}
@
I have just created a vector \verb@V01@ with all the integers from 1 to 100! You need to have a look at the sourcecode of firstDemo.Rnw to see how I did
But now you didn't see it. I typed \begin{tabbing} this. I will explain this and give more examples over the next weeks. For now
- 1/3 - - 2/3 -
You need to have a look at the sourcecode of firstDemo.Rnw to see how I did
this. I will explain this and give more examples over the next weeks. For now

firstDemo.Rnw 2009-01-06
I am really happy with the results of my experiments today.

See you soon!

\end{document}

- 3/3 -

Você também pode gostar