evalCapture
From R.utils v1.9.6
by Henrik Bengtsson
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 tosource
(). - 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. IfNULL
, the rows are not collapsed.
Value
- Returns a
character
string class 'CapturedEvaluation'.
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"
Community examples
Looks like there are no examples yet.