[R] Using substitute on a function parameter

William Dunlap wdunlap at tibco.com
Wed Sep 7 23:29:48 CEST 2011

I have used do.call("substitute", ...) to work around the
fact that substitute does not evaluate its first argument:

  R> z <- quote(func(arg))
  R> do.call("substitute", list(z, list(func=quote(myFunction), arg=as.name("myArgument"))))

S+'s substitute (following S version 4) has a third argument, evaluate, which controls
whether the first argument is evaluated or not:

  S+> z <- quote(func(arg))
  S+> substitute(z, list(func=quote(myFunction), arg=as.name("myArgument")), evaluate=TRUE)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Saptarshi Guha
> Sent: Wednesday, September 07, 2011 2:21 PM
> To: R-help at r-project.org
> Subject: [R] Using substitute on a function parameter
> Hello,
> I would like to write a function where substitute operates on the
> parameter, but ...
> > Expression =  function(o,l)  substitute(o, l)
> > Expression({x=.(FOO)}, list(FOO=2))
> o
> How do i get substitute to work on the contents of o.
> Regards
> Saptarshi
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list