capture(expression, collapse=NULL) texteval(sourceText, collapse=NULL, echo=TRUE) printed(sourceText, collapse=NULL)
collapseis non-NULL, otherwise a vector of character strings.
capturecaptures the results of executing
printedparse and evaluate the contents of sourceText using
sourceand the results are captured using a
collapseis NULL, a vector of strings is returned, one element for each line of output. (Empty strings for blank lines). If
collapseis non-NULL, the a single character string is formed by pasting the individuals elements together separated by this value. When
textevalwill return a transcript that includes both printed output and evaluated commands. When
textevalwill return only the printed output.
printedalways returns only the printed output.
These functions were created to allow strings provided from external processes (for example by rpy or RSPerl) to be evaluated as if they were scripts.
# define a script string script <- "x <- rnorm(100) y <- x + rnorm(100,0.25) summary(lm(y~x))" # evaluate the script string, returning a transcript. result <- texteval(script, "") cat(result) # evaluate the script string, returning the printed output. result <- printed(script, "") cat(result)