This function takes text(s) of R code and evals all at one run - returning a list with four elements. See Details.
Usage
eval.msgs(
src,
env = NULL,
showInvisible = FALSE,
graph.unify = evalsOptions("graph.unify")
)Arguments
- src
character values containing R code
- env
environment where evaluation takes place. If not set (by default), a new temporary environment is created.
- showInvisible
return
invisibleresults?- graph.unify
should
eval.msgstry to unify the style of (latticeandggplot2) plots? If set toTRUE(by default), somepanderOptions()would apply. Please note that this argument has no effect onbaseplots, useevalsinstead.
Value
a list of parsed elements each containing: src (the command run), result (R object: NULL if nothing returned), printed output, type (class of returned object if any), informative/wawrning and error messages (if any returned by the command run, otherwise set to NULL) and possible stdoutt value. See Details above.
Details
eval.msgs returns a detailed list of the result of evaluation:
src - character vector of specified R code.
result - result of evaluation.
NULLif nothing is returned. If any R code returned an R object while evaluating then the last R object will be returned as a raw R object. If a graph is plotted in the end of the given R code (remember: last R object), it would be automatically printed (see e.g.latticeandggplot2).output - character vector of printed version (
capture.output) ofresulttype - class of generated output. 'NULL' if nothing is returned, 'error' if some error occurred.
msg - possible messages grabbed while evaluating specified R code with the following structure:
messages - character vector of possible diagnostic message(s)
warnings - character vector of possible warning message(s)
errors - character vector of possible error message(s)
stdout - character vector of possibly printed texts to standard output (console)
Examples
if (FALSE) { # \dontrun{
eval.msgs('1:5')
eval.msgs('x <- 1:5')
eval.msgs('lm(mtcars$hp ~ mtcars$wt)')
## plots
eval.msgs('plot(runif(100))')
eval.msgs('histogram(runif(100))')
## error handling
eval.msgs('runiff(23)')
eval.msgs('runif is a nice function')
eval.msgs('no.R.object.like.that')
## messages
eval.msgs(c('message("FOO")', '1:2'))
eval.msgs(c('warning("FOO")', '1:2'))
eval.msgs(c('message("FOO");message("FOO");warning("FOO")', '1:2'))
eval.msgs('warning("d");warning("f");1')
## stdout
eval.msgs('cat("writing to console")')
eval.msgs('cat("writing to console");1:4')
} # }