Evaluate with messages
This function takes text(s) of R code and eval
s all at one run - returning a list with four elements. See Details
.
eval.msgs(src, env = NULL, showInvisible = FALSE, graph.unify = evalsOptions("graph.unify"))
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 |
graph.unify |
should |
eval.msgs
returns a detailed list of the result of evaluation:
src - character vector of specified R code.
result - result of evaluation. NULL
if 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. lattice
and ggplot2
).
output - character vector of printed version (capture.output
) of result
type - 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)
a list of parsed elements each containing: src
(the command run), result
(R object: NULL
if nothing returned), print
ed 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 stdout
t value. See Details above.
## Not run: 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') ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.