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

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

On 6/8/07, Duncan Murdoch <> 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 mailing list PLEASE do read the posting guide 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 Please read the posting guide before posting to the list.