Rev 35751 | 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 afrontend to \code{Sweave} using a simple driver by default, whichdiscards the documentation and concatenates all code chunks thecurrent 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 be a collection of hook functions. For each logicaloption of a code chunk (\code{echo}, \code{print}, \ldots) a hook canbe specified, which is executed if and only if the respective optionis \code{TRUE}. Hooks must be 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, thenit would be executed before the code in eachfigure chunk. This is especially useful to set defaults for thegraphical parameters in a series of figure chunks.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: Sweave User Manual, 2002\cr\url{http://www.ci.tuwien.ac.at/~leisch/Sweave}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("Sweave", "Sweave-test-1.Rnw", package = "utils")## 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}