[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-devel
Subject:    Re: [Rd] Version of substitute that evaluates it's first argument
From:       William Dunlap <wdunlap () tibco ! com>
Date:       2012-07-27 22:18:57
Message-ID: E66794E69CFDE04D9A70842786030B932DEEE1 () PA-MBX01 ! na ! tibco ! com
[Download RAW message or body]

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@r-project.org [mailto:r-devel-bounces@r-project.org] On Behalf
> Of Hadley Wickham
> Sent: Friday, July 27, 2012 2:53 PM
> To: r-devel@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@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic