1 / 11

Sweave

Sweave. Adele Cutler. Sweave. Friedrich Leisch Department of Statistics Ludwig-Maximilians-Universität München http://www.statistik.lmu.de/~leisch/. What is Sweave?. Sweave is a framework for mixing high quality typesetting (LaTeX) code (R) graphs/tables/output

rendor
Download Presentation

Sweave

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 Sweave() Stangle() Small.SNW.tex Small.SNW.R 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 <<name>>= • 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 <<name,opt1=val1,…,optn=valn>>=

  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: <<a>>= x=10 @ <<b>>= x+y @ <<c>>= <<a>> y=20 <<b>> @ Is equivalent to <<c>>= 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

More Related