[R] Evaluating expresssions as parameter values

Erich Neuwirth erich.neuwirth at univie.ac.at
Thu Oct 1 16:01:55 CEST 2009


Let us walk through my problem step by step:

1.
print(xyplot(yield ~ variety | site,groups=year,data=barley))
2.
print(xyplot(as.formula("yield ~ variety |  
site"),groups=year,data=barley))

The above two statements work, the next one does not work

3.
print(xyplot(as.formula("yield ~ variety | site"),groups=parse 
(text="year"),data=barley))

But the following one works

4.
arglist<-list(as.formula("yield ~ variety | site"),groups=parse 
(text="year"),data=barley)
print(do.call("xyplot",arglist))


why does 3 not work and 4 work?
Is there a way of coercing the string "year" into something which can  
directly be used in
3 as the argument used with groups= ???


The next one

print(xyplot(as.formula("yield ~ variety | site"),groups=eval(parse 
(text="year")),data=barley))

also works, but in this case the groups expression is evaluated before  
xyplot is applied,
and I think this is bad style (at least, if not worse).


On Sep 30, 2009, at 1:20 PM, Deepayan Sarkar wrote:

> xyplot(Sepal.Length ~ Petal.Length, iris, groups = ~Species)




More information about the R-help mailing list