From hadley at rice.edu  Fri Jul 27 23:53:18 2012
From: hadley at rice.edu (Hadley Wickham)
Date: Fri, 27 Jul 2012 14:53:18 -0700
Subject: [Rd] Version of substitute that evaluates it's first argument
Message-ID: <CABdHhvFstF51xCxPHLZssh0A6ORH9PfVi2W=ZyonrF=X4XxRPQ@mail.gmail.com>

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")))

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



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