[R] altering a "call" variable from quote()
David Winsemius
dwinsemius at comcast.net
Mon Mar 28 18:01:23 CEST 2011
On Mar 28, 2011, at 11:32 AM, William Dunlap wrote:
>> -----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.
Or `bquote`:
b = quote(b==3)
bquote(.(b) && x > 2)
# b == 3 && x > 2
> identical(e1,e2) &&
+ identical(e1,e3) &&
+ identical(e1, bquote(.(b) && x > 2) )
[1] TRUE
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list