texteval: Evaluate string(s) containing R commands and return the text...

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

View source: R/texteval.R

Description

Evaluate string(s) containing R commands and return the text transcript or printed results

Usage

1
2
3
capture(expression, collapse=NULL)
texteval(sourceText, collapse=NULL, echo=TRUE)
printed(sourceText, collapse=NULL)

Arguments

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

Details

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.

Value

A single character string if collapse is non-NULL, otherwise a vector of character strings.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

source, textConnection, sink, parse, eval

Examples

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

session documentation built on May 1, 2019, 10:11 p.m.

Related to texteval in session...