[R] call step inside a function

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Oct 4 23:57:08 CEST 2004


On Mon, 4 Oct 2004, Thomas Lumley wrote:

> 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.

Previously it just ignored the environment of the formula, which was not
part of the search when it and add1.glm were originally written.  
($call$formula has no environment.)  It needs updating (and probably
drop1.glm too).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list