Skip to content
Prev 18530 / 63424 Next

A problem with glm() and possibly model-using functions in general?

On Fri, 18 Nov 2005, Byron Ellis wrote:

            
Yes, there is a reason you'd actually want this behaviour, and 
it is documented. In help(model.frame) it says

      All the variables in 'formula', 'subset' and in '...' are looked
      for first in 'data' and then in the environment of 'formula' (see
      the help for 'formula()' for further details) and collected into a
      data frame.

In your example the environment of 'formula' is the global environment, 
since that's where it was created.

There isn't a set of scoping rules for formulas that will make everyone 
happy, but this lexical scope is what R has done for quite some time.

 	-thomas