Firstdemo.rnw

  • Uploaded by: Karsten D. Wolf
  • 0
  • 0
  • December 2019
  • PDF

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


Overview

Download & View Firstdemo.rnw as PDF for free.

More details

  • Words: 505
  • Pages: 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

\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 <>= plot(xx, yy, type="n", xlab="Time", ylab="Distance") polygon(xx, yy, col="gray") title("Distance Between Brownian Motions") @ \begin{figure} \begin{center} <>= <> @ \end{center} \caption{Distance between brownian motions} \label{fig:one} \end{figure} 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 - 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 -

More Documents from "Karsten D. Wolf"

Firstdemo.rnw
December 2019 4
First Demo
December 2019 6
3. C.docx
December 2019 17