Sweave is a system for combining S (or R) code with LaTeX in a single document.
Sweave is a system for combining r (or s) code with latex in a single document. It is an implementation of Donald Knuth's literate-programming concept. For new projects, consider using knitr instead, which is faster and provides more flexibility.
The Sweave file contains normal LaTeX code with R code chunks in it using the following syntax:
<<option1=TRUE,option2=3>>=
R code here
@
Generating a pdf from a Sweave file (generally with a .Rnw
extension in R) is a two stage process:
- Running
Sweave
on theRnw
file, which evaluates the code chunks and generates atex
file. - Compile the resulting
tex
file using e.g.pdflatex
.
Sweave offers easy integration of R code into any LaTeX document and makes reproducible-research easier.