[R] glm: formula vs character

Thomas Lumley tlumley at u.washington.edu
Sun Sep 19 05:52:07 CEST 2010


On Fri, 17 Sep 2010, Greg Snow wrote:

> I think what is going on (and someone is likely to correct me otherwise) is that formulas have an associated environment that gets passed along with them while character strings do not.
>

Yes.

model.frame(), which is called from most modelling functions, uses the data= argument as the first place to look up variables in the formula and the environment of the formula as the fallback location.

In the most common case, the environment of the formula is the environment from which the modelling function was called, so this is the same as using parent.frame(), but in more complex cases it is different.

     -thomas

Thomas Lumley
Professor of Biostatistics
University of Washington, Seattle



More information about the R-help mailing list