substitute
Substitute in an Expression

Description

Returns an expression with subsitutions made relative to an environment.

Usage

substitute(expr, env, evaluate=FALSE)

Arguments

expr an expression.
env an environment or a list that, if supplied, is used to make the substitutions. More commonly, it is omitted and the local environment of the function calling substitute is used.
evaluate a logical value. If TRUE, expr is evaluated before the substitution is done. The default is FALSE.

Details

Each occurence of a name in the expression is subsituted as follows:
Value
returns an object containing the unevaluated expr, with any names occurring in expr replaced by the corresponding component of env.
returns expr as a parsed but unevaluated object if no name matches occur. In this case, the result is equivalent to expression(expr)[[1]].
See Also
expression, sys.call, deparse, deparseText, substituteDirect.
Examples
# argument x as a character string label
f <- function(x) {
  label <- deparse(substitute(x))
  label
}
f(1:3+4)
# [1] "1:3 + 4"

# use evaluate argument to evaluate expr argument. f <- Response ~ .^2 - . expr <- quote(A+B+C) substitute(f, list(. = expr)) # returns name: f substitute(f, list(. = expr), evaluate=TRUE) # returns expression: Response ~ (A + B + C)^2 - (A + B + C)

Package base version 6.1.4-13
Package Index