From wdunlap at tibco.com  Sat Jul 28 00:18:57 2012
From: wdunlap at tibco.com (William Dunlap)
Date: Fri, 27 Jul 2012 22:18:57 +0000
Subject: [Rd] Version of substitute that evaluates it's first argument
In-Reply-To: <CABdHhvFstF51xCxPHLZssh0A6ORH9PfVi2W=ZyonrF=X4XxRPQ@mail.gmail.com>
References: <CABdHhvFstF51xCxPHLZssh0A6ORH9PfVi2W=ZyonrF=X4XxRPQ@mail.gmail.com>
Message-ID: <E66794E69CFDE04D9A70842786030B932DEEE1@PA-MBX01.na.tibco.com>

For what it's worth, S+'s substitute() has had an evaluate=FALSE argument
to substitute() for quite a while (I think it came with Sv4).  evaluate=TRUE
means to evaluate its first arument:
  > myCall <- call("myFunc", as.name("arg1"))
  > substitute(myCall, list(arg1=as.name("newArg1")), evaluate=TRUE)
  myFunc(newArg1)
  > substitute(myCall, list(arg1=as.name("newArg1")))
  myCall
It seems like a good name for the option and it is handy.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

> -----Original Message-----
> From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf
> Of Hadley Wickham
> Sent: Friday, July 27, 2012 2:53 PM
> To: r-devel at r-project.org
> Subject: [Rd] Version of substitute that evaluates it's first argument
> 
> 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/
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



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