Substitute in an Expression

DESCRIPTION:

Returns an object like expr but with substitutions made relative to frame .

USAGE:

substitute(expr, frame=<<see below>>) 

REQUIRED ARGUMENTS:

expr
a S-PLUS expression.

OPTIONAL ARGUMENTS:

frame
an object of mode list; if supplied, it is treated as the frame in which the substitution is done. More commonly, it is omitted and the local frame of the function calling substitute is used.

VALUE:

an object containing the unevaluated expr, with any names occurring in expr replaced by the corresponding component of frame.

If no name matches occur, expr is returned as a parsed, but unevaluated object. In this case the result is equivalent to expression(expr)[[1]]

DETAILS:

If the name was a formal argument to the function calling substitute, then the expression for that argument will be substituted-either the actual or the default expression. This substitution is unaffected by whether the argument has been evaluated yet. Any other names occurring in frame will also be substituted with their local assigned values. Names that are not found in frame will be left alone.

SEE ALSO:

, , , .

EXAMPLES:

# argument x as a character string label 
label <- deparse(substitute(x)) 
# x2 in f2 is the x value in f1 
f1 <- function(x, ...) { 
        f2 <- function(x2=substitute(x, sys.nframe() - 1), ...) 
        ... } 
# in the following case, x in the f2 definition will be looked for  
# in the session frame and on the search list only 
f1 <- function(x, ...) { 
        f2 <- function(x2=x, ...) 
        ... }