Sweave - PowerPoint PPT Presentation

About This Presentation
Title:

Sweave

Description:

R chunks start with name = Global options can be added using ... anywhere in a LaTeX chunk. Options can be added to a single R chunk using ... – PowerPoint PPT presentation

Number of Views:139
Avg rating:3.0/5.0
Slides: 12
Provided by: math75
Learn more at: http://www.math.usu.edu
Category:
Tags: chunk | sweave

less

Transcript and Presenter's Notes

Title: Sweave


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.R
Small.SNW.tex
LaTeX with R results
R commands only
7
Writing Sweave Files (_Snw)
  • LaTeX chunks start with _at_ and are just standard
    LaTeX.
  • To include scalars in text, use \Sexprexpr,
    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 ltltnamegtgt
  • Global options can be added using
  • \SweaveOptsopt1val1,,optnvaln
  • anywhere in a LaTeX chunk.
  • Options can be added to a single R chunk using
  • ltltname,opt1val1,,optnvalngtgt

9
Useful Options
  • echoFALSE prevents the R code from showing up in
    the LaTeX file.
  • figTRUE creates EPS and PDF files corresponding
    to the plots and inserts the relevant command
    into the LaTeX file.
  • resultshide
  • evalfalse

10
Named R chunks
  • R chunks can be named and reused
  • ltltagtgt
  • x10
  • _at_
  • ltltbgtgt
  • xy
  • _at_
  • ltltcgtgt
  • ltltagtgt
  • y20
  • ltltbgtgt
  • _at_

Is equivalent to ltltcgtgt x10 y20 xy _at_
11
For More Information
  • Read the FAQ
  • http//www.statistik.lmu.de/leisch/Sweave/FAQ.htm
    l
  • Read the Manual
  • http//www.statistik.lmu.de/leisch/Sweave/Sweave-
    manual.pdf
Write a Comment
User Comments (0)
About PowerShow.com