Re: [R] converting result of substitute to 'ordidnary' expression

From: Gabor Grothendieck <>
Date: Fri, 25 Jun 2010 23:40:09 -0400

On Fri, Jun 25, 2010 at 8:59 PM, Vadim Ogranovich <> wrote:
> Dear R users,
> As substitute() help page points out:
>     Substituting and quoting often causes confusion when the argument
>     is 'expression(...)'. The result is a call to the 'expression'
>     constructor function and needs to be evaluated with 'eval' to give
>     the actual expression object.
> And indeed I am confused. Consider:
>> dat <- data.frame(x=1:10, y=1:10)
>> subsetexp <- substitute(a<x, list(a=5))
> ## this doesn't work
>> subset(dat, subsetexp)
> Error in, subsetexp) :
>  'subset' must evaluate to logical
> ## this does work (thanks to the help page), but one needs to remember to call eval
>> subset(dat, eval(subsetexp))

If its ok to call it this way then it works without the eval:, list(dat, subsetexp)) mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sat 26 Jun 2010 - 03:44:41 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 Sat 26 Jun 2010 - 04:50:37 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive