capture {gtools} | R Documentation |
Capture printed output of an R expression in a string
capture(expression, collapse = "\n") sprint(x,...)
expression |
R expression whose output will be captured. |
collapse |
Character used to join output lines. Defaults to
"\n". Use NULL to return a vector of individual output lines. |
x |
Object to be printed |
... |
Optional parameters to be passed to print |
The capture
function uses sink
to capture the
printed results generated by expression
.
The function sprint
uses capture
to redirect the
results of calling print
on an object to a string.
A character string, or if collapse==NULL
a vector of character
strings containing the printed output from the R expression.
R 1.7.0+ includes capture.output
, which
duplicates the functionality of capture
. Thus, capture
is depreciated.
Gregory R. Warnes greg@random-technologies-llc.com
# capture the results of a loop loop.text <- capture( for(i in 1:10) cat("i=",i,"\n") ) loop.text # put regression summary results into a string data(iris) reg <- lm( Sepal.Length ~ Species, data=iris ) summary.text <- sprint( summary(reg) ) cat(summary.text)