evalCapture

0th

Percentile

Evaluates an expression and captures the code and/or the output

Evaluates an expression and captures the code and/or the output.

Keywords
utilities
Usage
evalCapture(expr, code=TRUE, output=code, ..., trim=TRUE, collapse="
", envir=parent.frame())
Arguments
expr
The expression to be evaluated.
...
Additional arguments passed to sourceTo which in turn passes arguments to source().
code
If TRUE, the deparsed code of the expression is echoed.
output
If TRUE, the output of each evaluated subexpression is echoed.
envir
The @enviroment in which the expression is evaluated.
trim
If TRUE, the captured rows are trimmed.
collapse
A character string used for collapsing the captured rows. If NULL, the rows are not collapsed.
Value

  • Returns a character string class 'CapturedEvaluation'.

Aliases
  • evalCapture
Examples
print(evalCapture({
 n <- 3;
 n;

 for (kk in 1:3) {
   printf("Iteration #%d
", kk);
 }

 print(Sys.time());

 type <- "horse";
 type;
}))

## > n <- 3
## > n
## [1] 3
## > for (kk in 1:3) {
## +     printf("Iteration #\%d\n", kk)
## + }
## Iteration #1
## Iteration #2
## Iteration #3
## > print(Sys.time())
## [1] "2011-11-06 11:06:32 PST"
## > type <- "horse"
## > type
## [1] "horse"
Documentation reproduced from package R.utils, version 1.23.2, License: LGPL (>= 2.1)

Community examples

Looks like there are no examples yet.