[Rd] expand.model.frame fails when call creating model has no data (PR#1423)
jfox@mcmaster.ca
jfox@mcmaster.ca
Fri, 29 Mar 2002 16:59:26 +0100 (MET)
I've encounted a problem using expand.model.frame. To illustrate, consider
the function
> test <- function(model){
+ expand.model.frame(model, "income")
+ }
>
The data frame Prestige (from the car library) has several variables,
including prestige, income and education. I've attached this data frame and
fit the following model
> mod.1 <- lm(prestige ~ (log(income) + education)*type)
>
From the documentation for expand.model.frame, the default environment in
which "things" are evaluated is environment(formula(model)), where model is
the first argument to expand.model frame; in this case
> environment(formula(mod.1))
<environment: R_GlobalEnv>
>
When I call the test function with mod.1, however, I get the following error:
> test(mod.1)
Error in eval(expr, envir, enclos) : Object "prestige" not found
>
But if I fit the same model specifying the data argument to lm as Prestige,
then test works,
> mod.2 <- lm(prestige ~ (log(income) + education)*type, data=Prestige)
> test(mod.2)
prestige log(income) education type income
GOV.ADMINISTRATORS 68.8 9.421492 13.11 prof 12351
GENERAL.MANAGERS 69.1 10.161187 12.26 prof 25879
ACCOUNTANTS 63.4 9.134647 12.77 prof 9271
. . .
TYPESETTERS 42.2 8.773694 10.00 bc 6462
BOOKBINDERS 35.2 8.193400 8.55 bc 3617
>
even though
> environment(formula(mod.2))
<environment: R_GlobalEnv>
>
that is, still the global environment.
I'm able to get expand.model.frame to do what I think it's supposed to do
by replacing the line
rval <- eval(call("model.frame", ff, data = data, subset = subset,
na.action = I), envir)
with
rval <- if (is.null(data)) eval(call("model.frame", ff, subset =
subset, na.action = naa), envir)
else eval(call("model.frame", ff, data = data, subset =
subset, na.action = naa), envir)
--please do not edit the information below--
Version:
platform = i386-pc-mingw32
arch = x86
os = Win32
system = x86, Win32
status =
major = 1
minor = 4.1
year = 2002
month = 01
day = 30
language = R
Windows 2000 Professional (build 2195) Service Pack 2.0
Search Path:
.GlobalEnv, Prestige, package:lattice, package:grid, package:car,
package:ctest, Autoloads, package:base
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._