[Rd] Version of substitute that evaluates it's first argument

Hadley Wickham hadley at rice.edu
Fri Jul 27 23:53:18 CEST 2012

Hi all,

Does there already exist a version of substitute that evaluates it's
first argument? (i.e. it accepts an already quoted expression).  This
seems like something that's pretty handy, but I haven't found any
existing function to do it:

substitute_e <- function(expr, env) {
  eval(substitute(substitute(expr, env), list(expr = expr)))

f <- quote(x + y + z)

substitute(f, list(y = 1, z = as.name("b")))
substitute_e(f, list(y = 1, z = as.name("b")))


Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University

More information about the R-devel mailing list