[R] Calling substitute(expr, list(a=1)) when expr <- expression(a+b+c)

Gabor Grothendieck ggrothendieck at gmail.com
Fri Nov 26 15:18:47 CET 2010


On Fri, Nov 26, 2010 at 8:48 AM, Søren Højsgaard
<Soren.Hojsgaard at agrsci.dk> wrote:
> Thanks, but I think there is a small mistake in your code:
>
>> expr <- expression(a+b+c)
>> do.call("substitute", list(expr, list(a=1)))
> expression(a + b + c)
>
> I think it should be:
>> as.expression(do.call("substitute", list(expr[[1]], list(a=1))))

Its already an expression so the extra as.expression would serve no purpose:

> identical(as.expression(do.call("substitute", list(expr, list(a=1)))),
+ do.call("substitute", list(expr, list(a=1))))
[1] TRUE





-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list