[R] Evaluating expresssions as parameter values

Gabor Grothendieck ggrothendieck at gmail.com
Tue Sep 22 21:17:31 CEST 2009


Try this:


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

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


On Tue, Sep 22, 2009 at 3:03 PM, Erich Neuwirth
<erich.neuwirth at univie.ac.at> wrote:
> I need to play games with an expression similar to the following one:
>
> print(xyplot(DepVar ~ Group|Covar, groups=Othergroup,
>        data=mydf, pch = 18 ,main="Testcase",auto.key = TRUE))
>
>
> The problem is that  the formula argument (the first argument)
> an the groups argument are passed over from another program as strings.
>
> The formula argument does not pose problems,
> I can do as.formula("DepVar ~ Group|Covar")
> bit I could not find an equivalent technique for the groups parameter.
> as.expression(... does not work and neither does
> parse(text=...
>
> Is there a way of accomplishing what I need?
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list