Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sweave Adele Cutler. Sweave Friedrich Leisch Department of Statistics Ludwig-Maximilians-Universität München

Similar presentations


Presentation on theme: "Sweave Adele Cutler. Sweave Friedrich Leisch Department of Statistics Ludwig-Maximilians-Universität München"— Presentation transcript:

1 Sweave Adele Cutler

2 Sweave Friedrich Leisch Department of Statistics Ludwig-Maximilians-Universität München http://www.statistik.lmu.de/~leisch/

3 What is Sweave? Sweave is a framework for mixing – –high quality typesetting (LaTeX) – –code (R) – –graphs/tables/output so that the report can be automatically re-created when the results or methodology change.

4 How Sweave Works: The author writes an Sweave file, an ordinary text file ending in SNW, containing   chunks of R   chunks of LaTeX   bits of glue that control everything Sweave creates a LaTeX file with the R code replaced, if desired, by its output. Stangle creates a file with just the R code (ready to be run in R).

5 Example Create an Sweave file called “small.SNW” and go into R. The R command Sweave(“small.SNW”) produces a new file called “small.SNW.tex”. We can now run LaTex in the usual way. The R command Stangle(“small.SNW”) produces a new file called “small.SNW.R”. We could execute these commands using source(“small.SNW.R”) from inside R.

6 Sweave Small.SNW Small.SNW.RSmall.SNW.tex Sweave()Stangle() LaTeX with R results R commands only

7 Writing Sweave Files (_Snw)   LaTeX chunks start with @ and are just standard LaTeX.   To include scalars in text, use \Sexpr{ expr }, where expr is an R expression returning a vector, the first element of which will be printed in the LaTeX.

8 Writing Sweave Files (continued)   R chunks start with >=   Global options can be added using \SweaveOpts{opt1=val1,…,optn=valn} anywhere in a LaTeX chunk.   Options can be added to a single R chunk using >=

9 Useful Options echo=FALSE prevents the R code from showing up in the LaTeX file. fig=TRUE creates EPS and PDF files corresponding to the plots and inserts the relevant command into the LaTeX file. results=hide eval=false

10 Named R chunks   R chunks can be named and reused: >= x=10 @ >= x+y @ >= > y=20 > @ Is equivalent to >= x=10 y=20 x+y @

11 For More Information: Read the FAQ: http://www.statistik.lmu.de/~leisch/Sweave/FAQ.html Read the Manual: http://www.statistik.lmu.de/~leisch/Sweave/Sweave-manual.pdf


Download ppt "Sweave Adele Cutler. Sweave Friedrich Leisch Department of Statistics Ludwig-Maximilians-Universität München"

Similar presentations


Ads by Google