[R] expand.model.frame gives "object not found"

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Oct 1 15:20:23 CEST 2004


Why are you using expand.model.frame to update a *formula*?  That is what 
update()'s formula method does.

It is rather rare to use expand.model.frame() directly.  As ever, we 
recommend reading a good book on R as applied to whatever you are trying 
to do -- several of them have examples of using update().


On Thu, 30 Sep 2004, David Hugh-Jones wrote:

> Hello,
> 
> I am a (relatively) experienced programmer, but new to R.

In short, inexperienced with R or languages like R.

> I have a problem using R 1.9.1. I have fit some data using glm(), from
> within a function:
> 
>         formula = as.formula(paste(depvarname, "~", rhs), env=globalenv())
>         return (glm(formula, family=binomial(link=logit)))
> 
> I have now come back to the formula and want to add some more
> variables to it. So I do:
> 
> expand.model.frame(formulaname, ~ new_variable)
> 
> but I get the response
> 
> Error in eval(expr, envir, enclos) : Object "foreignaid.dummy" not found
> 
> where foreignaid.dummy is my dependent variable. However,
> foreignaid.dummy is clearly visible in the global environment:
> 
> > ls(pat="foreignaid.dummy", envir=globalenv())
>  [1] "foreignaid.dummy"
>  ...
> 
> So why is my dependent variable lost?
> 
> I have read the earlier comments on the same topic, but they seem to
> indicate that a previous bug was fixed. Am I missing the point about
> scoping?
> 
> Any help much appreciated.
> 
> David Hugh-Jones
> Essex University Govt Dept
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 
> 

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