Evaluate an Expression

DESCRIPTION:
Evaluates an S-PLUS expression. The frame in which the evaluation is to take place can be specified.

USAGE:
eval(expression, local=T, parent=<<see below>>)

REQUIRED ARGUMENTS:
expression:
any S-PLUS expression

OPTIONAL ARGUMENTS:
local:
the frame in which to do the evaluation; by default, the frame of the caller of eval. If local is FALSE, evaluation is done in the global frame. Otherwise, local can be either a numeric value, interpreted as one of the frames of the evaluator, or it can be an explicit list, with the named elements of the list defining the bindings for the names occurring in the expression. A typical numeric choice of local would be sys.parent(1), meaning the routine that called the routine calling eval.
parent:
the frame to use as the parent of the evaluation frame. This only needs to be supplied when unevaluated arguments are to be handled by a special arrangement (as required by browser). The parent argument is ignored if local is not a list.

VALUE:
the value of expression.

DETAILS:
If the expression you evaluate involves a function call, the evaluator typically creates a new frame in which to evaluate the function; if you want to access or affect the frame designated by local from the function your expression called, your function can use sys.parent in conjunction with assign or eval (see the examples section).

SEE ALSO:
call , parse .

EXAMPLES:
# a function that can simulate the S-PLUS program
# from inside a function: see section 7.4.3 of
# Becker, Chambers and Wilks
try.S <- function()
        print(eval(parse(), F))

# this test evaluates a function call, and makes assignments # into the caller's frame from the function called eval.test <- function() { x <- pi y <- runif(10) z <- 12 myfunc <- function() { # this assignment has no effect on parent frame's x x <- 1 assign("y", 2, frame = sys.parent(1)) eval(expression(z <- 3), local = sys.parent(1)) } old.values <- list(x = x, y = y, z = z) # creates new frame for myfunc eval(expression(myfunc()), local = T) new.values <- list(x = x, y = y, z = z) list(old.values = old.values, new.values = new.values) }