[Rd] variable scope in update(): bug or feature?

Michael wuolong at gmail.com
Thu Dec 21 18:08:15 CET 2006


I stumbled upon this when using update() (specifically update.lm()).  If
in the original call to lm(), say

a <- lm (y ~ x + z, data = mydata)

where y and z are in data frame mydata but x is in the global environment.

Then if later I run,

a0 <- update (a, ~ . - z)

a0$model will contain values of x in the global environment which may well
be different, even different length from mydata$y.  Somehow, update() pads
a0$model to have the same number of rows as the length of x.

I would think that it would desirable to use x as in a$model rather than the
global one.  

Is this a bug or a deliberate feature?

Thanks,

Michael



More information about the R-devel mailing list