Rserve.eval {Rserve}R Documentation

Evaluate expressions in a REPL-like fashion


Rserve.eval evaluates a given expression in a way that is very close to the behavior on the console Read/Evaluate/Print Loop (REPL). Among other things this means printing the result of each expression if visible. The function is guaranteed to not raise an error and in case of an error it returns an object of class Rserve-eval-error with details including the error and the stack trace.


Rserve.eval(what, where = .GlobalEnv, last.value = FALSE, exp.value = FALSE,
            context = NULL)



expressions to evaluate


environment to evaluate in


logical, if FALSE then the result of teh evaluation is returned, otherwise the evaluation is only performed for its side-efects and returns TRUE instead.


logical, it TRUE then an error object will include the actual expression that triggered the error, otherwise it will only store the index of the expression in what.


optional object that will be used as the context for the duration of the evaluation.


If what contains one or more expressions, they are evaluated one by one while printing the result of each if visible. Upon error subsequent expressions are not evaluated. If what is not an expression then the only a single evaluation of what is performed and the result is not printed.

The main purpose of this function is to implement console front-ends where the front-end uses parse() + Rserve.eval() to simulate the action of a GUI. Because the function returns in all circumstances it allows clients to rely on a well-define messaging behavior.


If the evaluation triggered an error, the result is an object of class Rserve-eval-error with components


character, error message


list of contexts in the traceback


if what contains multiple expressions then this will be either an index to the expression that caused the error (exp.value=FALSE) or the actual expression (otherwise).

If the evaluation finished without an error then the result is either TRUE if last.value=FALSE or the value of the last expression otherwise.


Simon Urbanek


  g <- function() stop("foo")
  f <- function() g()
  (Rserve.eval(quote(1+1), last.value=TRUE))

[Package Rserve version 1.8-6 Index]