Skip to content

Constructing logical expressions dynamically

2 messages · Tom Murray, Duncan Murdoch

#
On 02/07/2008 7:27 PM, Tom Murray wrote:
e1 is an object of class "expression":

 > class(e1)
[1] "expression"

It prints looking like a function call because R doesn't know any other 
way to print an expression.
e2 is not, it's an unevaluated function call:

 > class(e2)
[1] "call"

It really is a function call, as class() tells us.

If you evaluate it, you get something just like e1:

 > class(eval(e2))
[1] "expression"
The problem here is that eval(e2) is an expression; you need to evaluate 
it to get the logical vector, i.e.

d2 <- subset(data, eval(eval(e2)))

Duncan Murdoch