[R] update.default evaluating in wrong environment?

Martin C. Martin martin at martincmartin.com
Tue Oct 10 21:00:11 CEST 2006


Great; thanks for the detailed explanation!

- Martin

Thomas Lumley wrote:
> On Tue, 10 Oct 2006, Martin C. Martin wrote:
>> Thanks, or even just:
>>
>> e <- environment(formula(f.lm))
>>
>> But this was more of a bug report.  Is update.default wrong?  Should it
>> be changed?  I don't see how evaluating in update's parent environment
>> would ever be better default behavior than the formula's environment.
>>
> 
> This is deliberate (although that doesn't necessarily imply that it is 
> optimal). There already is a bug report (PR#1861) on this issue, so 
> another one certainly isn't appropriate.
> 
> The comments for this bug report give an example taken from the scripts 
> for MASS chapter 6, doing a bootstrap of a linear model
> ph.fun <- function(data, i) {
>   d <- data
>   d$calls <- d$fitted + d$res[i]
>   coef(update(fit, data=d))
> }
> 
> This is not uncommon for resampling and other perturbations of a model 
> and requires looking in the calling frame of update().
> 
> For other uses such as yours the right place would be the frame where 
> the model was created. Neither the environment of the formula nor the 
> calling frame of update() is guaranteed to be the right place and it is 
> easy to come up with examples where each works and the other doesn't.
> 
> There really isn't a trivial solution to this.
> 
>     -thomas



More information about the R-help mailing list