brew: Report Brewing For Text and R Output

Description Usage Arguments Details Value Author(s) See Also Examples

Description

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.

Usage

1
brew(file=stdin(),output=stdout(),text=NULL,envir=parent.frame(),run=TRUE)

Arguments

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.

Details

The following template contains syntax to exercise all brew functionality:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
---------------
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:

1
2
3
4
5
6
7
8
--------------
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.
--------------

Value

When run=TRUE, the result of the last evaluated expression after brewing the input. When run=FALSE, the parsed expressions after brewing the input.

Author(s)

Jeffrey Horner <jeff.horner@vanderbilt.edu>

See Also

Sweave for the original report generator.

Examples

1
2
3
4
5
6
7
8
9
## 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())

brew documentation built on May 2, 2019, 5:17 p.m.

Related to brew in brew...