texteval {session} | R Documentation |
Evaluate string(s) containing R commands and return the text transcript or printed results
capture(expression, collapse=NULL) texteval(sourceText, collapse=NULL, echo=TRUE) printed(sourceText, collapse=NULL)
expression |
R expression to be evaluated |
sourceText |
Vector of string to be evaluated. |
collapse |
Line separator. Defaults to NULL |
echo |
Should commands be shown in output. Defaults to
TRUE |
capture
captures the results of executing expression
using a textConnection
. texteval
and printed
parse and evaluate the contents of sourceText
using source
and the results are captured using a
textConnection
. If collapse
is NULL, a
vector of strings is returned, one element for each line of output.
(Empty strings for blank lines). If collapse
is non-NULL, the
a single character string is formed by pasting the individuals
elements together separated by this value. When echo
is TRUE,
texteval
will return a transcript that includes both printed
output and evaluated commands. When echo
is FALSE,
texteval
will return only the printed output. printed
always 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.
A single character string if collapse
is non-NULL, otherwise a
vector of character strings.
Gregory R. Warnes warnes@bst.rochester.edu
source
, textConnection
,
sink
, parse
, eval
# define a script string script <- "x <- rnorm(100)\ny <- x + rnorm(100,0.25)\nsummary(lm(y~x))" # evaluate the script string, returning a transcript. result <- texteval(script, "\n") cat(result) # evaluate the script string, returning the printed output. result <- printed(script, "\n") cat(result)