Learn R Programming

pander (version 0.6.5)

eval.msgs: Evaluate with messages

Description

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 invisible results?

graph.unify

should eval.msgs try to unify the style of (lattice and ggplot2) plots? If set to TRUE (by default), some panderOptions() would apply. Please note that this argument has no effect on base plots, use evals instead.

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

See Also

evals

Examples

Run this code
# 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')
# }

Run the code above in your browser using DataLab