[R] xyplot() groups scope issue

deepayan.sarkar at gmail.com deepayan.sarkar at gmail.com
Thu Aug 30 19:18:58 CEST 2007

On 8/30/07, Mike Lawrence <Mike.Lawrence at dal.ca> wrote:
> Hi all,
> Tinkering with a wrapper for xyplot that will help me plot a bunch of
> plots in a data analysis I'm doing and I ran into an odd error that
> I'm guessing is a scope issue. Here's a very simple version of the code:

It's indeed a scoping issue. For writing wrappers, the best solution
I've been able to come up with involves match.call() and
eval.parent(). See lattice:::dotplot.formula for a template.

If you really want to do it your way, try changing the environment of
the formula:

do.xyplot = function( plot.formula, data.frame, plot.groups){
        environment(plot.formula) <- environment() # new
                ,data = data.frame
                ,groups = eval(plot.groups)


More information about the R-help mailing list