brew {brew} | R Documentation |
brew
provides a templating system for text reporting. The syntax is similar to PHP,
Java Server Pages, Ruby's erb module, and Python's psp module.
brew(file=stdin(),output=stdout(),text=NULL,envir=parent.frame(),run=TRUE)
file |
A connection, or a character string naming the file to read from. stdin() is the default. |
output |
A connection, or a character string naming the file to print to. stdout() is the default. |
text |
A character string treated as if it contained lines of a file
to read from. Only one of file or text is used as input.
Default is NULL . |
envir |
the environment in which the input is to
be evaluated. Default is the caller's environment, useful for
nested brew calls. |
run |
Logical to determine if brew should evaluate the input (run=TRUE ) or
just parse it (run=FALSE ). Useful for debugging. |
The following template contains syntax to exercise all brew
functionality:
--------------- You won't see this R output, but it will run. <% foo <- 'bar' %> Now foo is <%=foo%> and today is <%=format(Sys.time(),'%B %d, %Y')%>. <%# Comment -- ignored -- useful in testing. Also notice the dash-percent-gt. It chops off the trailing newline. You can add it to any percent-gt. -%> % cat("and R one-liner\n") How about generating a template from a template? <%% foo <- 'fee fi fo fum' %%> foo is still <%=foo%>. ---------------
The output is:
-------------- You won't see this R output, but it will run. Now foo is bar and today is April 20, 2007. and R one-liner How about generating a template from a template? <% foo <- 'fee fi fo fum' %> foo is still bar. --------------
When run=TRUE
, the result of the last evaluated expression after brewing the input.
When run=FALSE
, the parsed expressions after brewing the input.
Jeffrey Horner <jeff.horner@vanderbilt.edu>
Sweave
for the original report generator.
## Don't sully up environment, so use envir=new.env(). Nested brew calls will still work. brew(system.file("example1.brew",package="brew"),envir=new.env()) ## Various ways to print R output brew(system.file("catprint.brew",package="brew"),envir=new.env()) rm(iris) ## The example from the Details section brew(system.file("featurefull.brew",package="brew"),envir=new.env())