Skip to content
Prev 39816 / 398498 Next

matching of arguments in ...?

On Wed, 5 Nov 2003, David Firth wrote:

            
This is a historical legacy of someone trying to be too helpful.

In lm() and similar functions there are some arguments that are
interpreted as if they were quoted expressions and then are looked up in
data= and in the calling frame (actually in environment(formulas)).

So

 lm(y~x, offset=z, data=df)

will work if z is either a column of df or a variable floating free in the
calling frame.

In order to make this rather unnatural evaluation work, lm and model.frame
have to play tricks with these arguments: they are explicitly evaluated in
environment(formula), in this case the environment inside test().

This sort of thing is why some of us strongly recommend not having
implicit dynamic scoping on new modelling functions, so eg in the survey
package the syntax looks like
  svydesign(id=~id, weights=~w, data=df)
with explicit formulas.  The other option is explicitly quoted
expressions.


	-thomas