Skip to content
Prev 214505 / 398500 Next

using a condition given as string in subset function - how?

When eval is given a parse tree (e.g., the output of
parse() or call()) it recursively ascends the tree,
effectively calling eval() on the subtrees.  E.g.,
parse(text='paste("No", 1)')[[1]] returns a "call" object
of length 3, the elements being the name object `paste`,
the character object "No", and the numeric object 1.
Evaluating a name object returns its value and evaluating
a character or numeric object returns the object (unchanged).
I.e., in this case
   eval(`paste`) -> function(..., sep=" ", collapse=NULL)
   eval("No") -> "No"
   eval(1) -> 1
The root of the parse tree is the call object and evaluating
that means applying the function given by the first argument
to the rest of the argumeents.

If eval("No") meant the same as eval(parse(text="No"))
then this scheme would break down, since you wouldn't be able
to distinguish between character objects and name objects,
so it would not be possible to say you wanted the string "No"
or the value of the object called "No".
 
You might say that eval("String") should do one thing when
called directly, whatever that means, and another when called
by a recursive call to eval(), but I think functions should
act the same no matter who calls them.

There are also times when you want the raw parse tree, as when
processing model formulae like log(response)~groupId/predictor
or trellis/lattice formulae like log(y)~predictor|groupId.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
???????????????????????????????????????????????????????
ct.org/posting-guide.html>