[R] Evaluating expresssions as parameter values

Gabor Grothendieck ggrothendieck at gmail.com
Tue Sep 22 22:27:47 CEST 2009


Try parse(text=...):

f <- function(fo, data, groups) {
	g <- do.call("xyplot", list(as.formula(fo),
		groups = parse(text = groups), data))
	print(g)
}

f("yield ~ variety | site", data = barley, groups = "year")



On Tue, Sep 22, 2009 at 4:20 PM, Erich Neuwirth
<erich.neuwirth at univie.ac.at> wrote:
> Thank you, this works for my example.
> On Sep 22, 2009, at 9:17 PM, Gabor Grothendieck wrote:
>
> f <- function(fo, data, groups) {
> g <- do.call("xyplot", list(as.formula(fo), groups = as.name(groups), data))
> print(g)
> }
>
> But xyplot allows expressions for the groups parameter also,
> and using as.expression instead of as.name in your example does not work.
> What is happening?
>
> f <- function(fo, data, groups) {
> g <- do.call("xyplot", list(as.formula(fo), groups = as.expression(groups),
> data))
> print(g)
> }
>
> f("yield ~ variety ~ site",barley,"year")
> produces a very nicely labeled but empty plot.
>




More information about the R-help mailing list