Re: [R] altering a "call" variable from quote()

From: William Dunlap <wdunlap_at_tibco.com>
Date: Mon, 28 Mar 2011 08:32:03 -0700

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Jack Tanner
> Sent: Sunday, March 27, 2011 9:14 PM
> To: r-help_at_stat.math.ethz.ch
> Subject: Re: [R] altering a "call" variable from quote()
>
> Jack Tanner <ihok <at> hotmail.com> writes:
>
> > > b = quote(b==3)
> >
> > Now I want to append "&& x > 2" to the value of b. How do I do that?
>
> Never mind, I figured it out:
>
> substitute(b && x > 2, list(b=b))

You can also use call() or as.call():

  > e1 <- substitute(b && x > 2, list(b=b))
  > e2 <- call("&&", b, quote(x>2))
  > e3 <- as.call(list(quote(`&&`), b, quote(x>2)))
  > identical(e1,e2) && identical(e1,e3)
  [1] TRUE
substitute can be a pain when the first argument is not a literal expression.

Bill Dunlap
Spotfire, TIBCO Software

wdunlap tibco.com

>
> ______________________________________________
> 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.
>



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. Received on Mon 28 Mar 2011 - 15:34:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Mar 2011 - 16:40:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive