[R] call step inside a function

Thomas Lumley tlumley at u.washington.edu
Mon Oct 4 23:32:15 CEST 2004


On Mon, 4 Oct 2004, weihong wrote:
>> program
> function(dataset)
> {
>        tmp<-glm(weta~1, family=poisson, data=dataset)
>        tmp.f<-step(tmp,~.+jd)
> }
>
> When I run program(data) in 1.9.0, an error message appears:
>
> Error in model.frame.default(formula = WETA ~ jd, data = dataset,
> drop.unused.levels = TRUE) :
>        Object "dataset" not found

Yes, it looks as though add1.glm is not putting the environment 
information in the same place that model.frame.glm is looking for it.

add1.glm sets up an empty shell of a glm object and calls model.frame.glm, 
but model.frame.glm uses the $terms component to specify the environment, 
and add1.glm doesn't give a $terms component.  Presumably at some time in 
the past model.frame.glm used the $call$formula  component instead.


 	-thomas




More information about the R-help mailing list