Re: [R] evaluating variables in the context of a data frame

From: Zack Weinberg <zackw_at_panix.com>
Date: Fri, 08 Jun 2007 11:45:18 -0700

On 6/8/07, Duncan Murdoch <murdoch_at_stats.uwo.ca> wrote:
> > After a bit more experimentation I figured out that this does what I want:
> >
> >> h <- function(x, d) eval(substitute(x), d, parent.frame())
> >
> > but I don't understand why the substitute() helps, or indeed why it
> > has any effect at all...
>
> Within the evaluation frame of h, x is a promise to evaluate an
> expression. substitute(x) extracts the expression. If you just use x,
> it gets evaluated in the frame from which h was called, rather than in a
> frame created from d.

Thanks, that's helpful. Could you comment on substitute() use in the message I just posted which contains the actual code I'm trying to get to work? In addition to the question asked there, after your explanation I still do not understand why

  g <- ...
  xyplot ( ..., groups=g, ... )

should refuse to find g, and the same thing with groups=substitute(g) works (well, gets farther before blowing up).

zw



R-help_at_stat.math.ethz.ch 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. Received on Fri 08 Jun 2007 - 19:10:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 08 Jun 2007 - 19:31:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.