[R] Use of expand.model.frame()

Thomas Lumley tlumley at u.washington.edu
Mon Jan 3 20:36:27 CET 2005


On Sat, 1 Jan 2005, Gabor Grothendieck wrote:

> Look at the source of expand.model.frame.
>
> The second line of expand.model.frame uses the data component of mod$call
> and if its not there expand.model.frame chokes.  As a workaround check
> if its missing and supply it yourself:
>
> if (is.null(mod$call$data)) mod$call$data <- environment(formula(mod))
> expand.model.frame(mod, "z")
>
> expand.model.frame should probably be doing that itself.
>

No, it shouldn't.

It should be setting data to as.list(NULL) if it is NULL.

I am surprised to find that
>  y<-1:10
> eval(quote(y), NULL, .GlobalEnv)
Error in eval(expr, envir, enclos) : Object "y" not found
> eval(quote(y), as.list(NULL), .GlobalEnv)
  [1]  1  2  3  4  5  6  7  8  9 10
> eval(quote(y), as.data.frame(NULL), .GlobalEnv)
Error in eval(quote(y), as.data.frame(NULL), .GlobalEnv) :
         attempt to set an attribute on NULL

The third of these is definitely a bug, and I thought the first used to 
work (and that I would have noticed when writing expand.model.frame if it 
didn't).

 	-thomas




More information about the R-help mailing list