Rev 4331 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{Sweave}\alias{Sweave}\alias{Stangle}\alias{SweaveSyntaxLatex}\alias{SweaveSyntaxNoweb}\encoding{latin1}\title{Automatic Generation of Reports}\description{\code{Sweave} provides a flexible framework for mixing text and S codefor automatic report generation. The basic idea is to replace the Scode with its output, such that the final document only contains thetext and the output of the statistical anlysis.}\usage{Sweave(file, driver = RweaveLatex(),syntax = getOption("SweaveSyntax"), ...)Stangle(file, driver = Rtangle(),syntax = getOption("SweaveSyntax"), ...)}\arguments{\item{file}{Name of Sweave source file.}\item{driver}{The actual workhorse, see details below.}\item{syntax}{An object of class \code{SweaveSyntax} or a characterstring with its name. The default installation provides\code{SweaveSyntaxNoweb} and \code{SweaveSyntaxLatex}.}\item{\dots}{Further arguments passed to the driver's setup function.}}\details{Automatic generation of reports by mixing word processing markup (likelatex) and S code. The S code gets replaced by its output (text orgraphs) in the final markup file. This allows to re-generate a reportif the input data change and documents the code to reproduce theanalysis in the same file that also produces the report.\code{Sweave} combines the documentation and code chunks together(or their output) into a single document. \code{Stangle} extracts onlythe code from the Sweave file creating a valid S source file (that canbe run using \code{\link{source}}). Code inside \code{\\Sexpr\{\}}statements is ignored by \code{Stangle}.\code{Stangle} is just a frontend to \code{Sweave} using a simpledriver by default, which discards the documentation and concatenatesall code chunks the current S engine understands.}\section{Hook Functions}{Before each code chunk is evaluated, a number of hook functions can beexecuted. If \code{getOption("SweaveHooks")} is set, it is taken to bea collection of hook functions. For each logical option of a code chunk(\code{echo}, \code{print}, \ldots) a hook can be specified, which isexecuted if and only if the respective option is \code{TRUE}. Hooks mustbe named elements of the list returned by\code{getOption("SweaveHooks")} and be functions taking noarguments. E.g., if option \code{"SweaveHooks"} is defined as\code{list(fig = foo)}, and \code{foo} is a function, then it would beexecuted before the code in each figure chunk. This is especially usefulto set defaults for the graphical parameters in a series of figurechunks.Note that the user is free to define new Sweave options and associatearbitrary hooks with them. E.g., one could define a hook function foroption \code{clean} that removes all objects in the globalenvironment. Then all code chunks with \code{clean = TRUE} would startoperating on an empty workspace.}\section{Syntax Definition}{Sweave allows a very flexible syntax framework for markingdocumentation and text chunks. The default is a noweb-style syntax, asalternative a latex-style syntax can be used. See the user manual fordetails.}\author{Friedrich Leisch}\references{Friedrich Leisch: Dynamic generation of statistical reports usingliterate data analysis. In W. \enc{Härdle}{Haerdle} andB. \enc{Rönz}{Roenz}, editors, Compstat 2002 - Proceedings in ComputationalStatistics, pages 575--580. Physika Verlag, Heidelberg, Germany,2002. ISBN 3-7908-1517-9.}\seealso{\code{\link{RweaveLatex}}, \code{\link{Rtangle}}}\examples{testfile <- system.file("examples", "Sweave-test-1.Rnw", package = "Sweave")## enforce par(ask=FALSE)options(par.ask.default=FALSE)## create a LaTeX fileSweave(testfile)## create an S source file from the code chunksStangle(testfile)## which can be simply sourcedsource("Sweave-test-1.R")\dontshow{if(!interactive()) unlink("Sweave-test-1*")}}\keyword{utilities}