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.

Usage
evalCapture(expr, code=TRUE, output=code, ..., trim=TRUE, collapse="",
  envir=parent.frame())

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.}

Returns a character string class 'CapturedEvaluation'.

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", kk) ## + ## Iteration #1 ## Iteration #2 ## Iteration #3 ## > print(Sys.time()) ## [1] "2011-11-06 11:06:32 PST" ## > type <- "horse" ## > type ## [1] "horse" }

[object Object]

utilities

Aliases
  • evalCapture
Documentation reproduced from package R.utils, version 1.28.4, License: LGPL (>= 2.1)

Community examples

Looks like there are no examples yet.