Automatic Generation of Reports
Sweave provides a flexible framework for mixing text and R/S code
for automatic report generation. The basic idea is to replace the
code with its output, such that the final document only contains the
text and the output of the statistical analysis: however, the source
code can also be included.
1 2 3 4 5
Path to Sweave source file. Note that this can be
supplied without the extension, but the function will only proceed
if there is exactly one Sweave file in the directory whose
The actual workhorse, see ‘Details’.
The default encoding to assume for
Further arguments passed to the driver's setup function:
see section ‘Drivers’,
Automatic generation of reports by mixing word processing markup (like latex) and S code. The S code gets replaced by its output (text or graphs) in the final markup file. This allows a report to be re-generated if the input data change and documents the code to reproduce the analysis in the same file that also produces the report.
Sweave combines the documentation and code chunks together (or
their output) into a single document.
Stangle extracts only
the code from the Sweave file creating an S source file that can be
source. (Code inside
statements is ignored by
Stangle is just a wrapper to
Sweave specifying a
different default driver. Alternative drivers can be used: the CRAN
package \CRANpkgcacheSweave and the Bioconductor package weaver
both provide drivers based on the default driver
RweaveLatex which incorporate ideas of caching
the results of computations on code chunks.
Environment variable SWEAVE_OPTIONS can be used to override the
initial options set by the driver: it should be a comma-separated set
key=value items, as would be used in a \SweaveOpts
statement in a document.
Non-ASCII source files must contain a line of the form
encoding = "bytes".
Sweave allows a flexible syntax framework for marking documentation and text chunks. The default is a noweb-style syntax, as alternative a latex-style syntax can be used. (See the user manual for further details.)
syntax = NULL (the default) then the available syntax
objects are consulted in turn, and selected if their
component matches (as a regexp) the file name. Objects
extension = "[.][rsRS]nw$") and
extension = "[.][rsRS]tex$") are
supplied, but users or packages can supply others with names matching
Friedrich Leisch and R-core.
Friedrich Leisch (2002) Dynamic generation of statistical reports using literate data analysis. In W. Härdle and B. Rönz, editors, Compstat 2002 - Proceedings in Computational Statistics, pages 575–580. Physika Verlag, Heidelberg, Germany, ISBN 3-7908-1517-9.
‘Sweave User Manual’, a vignette in the utils package.
Packages \CRANpkgcacheSweave, weaver (Bioconductor) and \CRANpkgSweaveListingUtils.
Further Sweave drivers are in, for example, packages \CRANpkgR2HTML, \CRANpkgascii, \CRANpkgodfWeave and \CRANpkgpgfSweave.
Non-Sweave vignettes may be built with
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
testfile <- system.file("Sweave", "Sweave-test-1.Rnw", package = "utils") ## enforce par(ask = FALSE) options(device.ask.default = FALSE) ## create a LaTeX file Sweave(testfile) ## This can be compiled to PDF by ## tools::texi2pdf("Sweave-test-1.tex") ## or outside R by ## R CMD texi2pdf Sweave-test-1.tex ## which sets the appropriate TEXINPUTS path. ## create an R source file from the code chunks Stangle(testfile) ## which can be sourced, e.g. source("Sweave-test-1.R")