From gregory_r_warnes@groton.pfizer.com  Thu Jun 14 19:15:54 2001
From: gregory_r_warnes@groton.pfizer.com (gregory_r_warnes@groton.pfizer.com)
Date: Thu, 14 Jun 2001 20:15:54 +0200 (MET DST)
Subject: [Rd] expand.model.frame() fails when subset is specified (PR#979)
Message-ID: <200106141815.UAA16660@pubhealth.ku.dk>

Full_Name: Gregory R. Warnes
Version: 1.2.0, 1.2.3
OS: SunOS gsun124 5.8 Generic_108528-03 sun4u sparc SUNW,Ultra-5_10
Submission from: (NULL) (12.18.36.49)


When using expand.model.frame on a model that specifies a subset selection, 
an error is generated on the variable used for the subset selection.  

Example:

> data <- data.frame(x=1:10,y=1:10,z=1:10,m=1:10)
> model <- lm( y ~ x, data=data, subset=m<8)
> expand.model.frame(model, ~ z)
Error in [.data.frame(structure(list(y = c(1, 2, 3, 4, 5, 6, 7, 8, 9,  : 
        Object "m" not found

The patch below uses "eval" and "call" with the appropriate
environment instead of calling model.frame directly. This results in:

> source("/home/warneg/R-src/R-1.2.3/src/library/base/R/expand.model.frame.R")
> expand.model.frame(model, ~ z)
  y x z
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
7 7 7 7

-Greg Warnes

---------START OF PATCH----------

diff -c R-1.2.3.orig/src/library/base/R/expand.model.frame.R
R-1.2.3/src/library
/base/R/expand.model.frame.R
*** R-1.2.3.orig/src/library/base/R/expand.model.frame.R        Mon Jun 11
16:30
:51 2001
--- /home/warneg/R-src/R-1.2.3/src/library/base/R/expand.model.frame.R  Mon Jun

11 16:30:51 2001
***************
*** 18,27 ****
      if (!na.expand){
          naa <- model$call$na.action
          subset <- model$call$subset
!         rval <- model.frame(ff, data=data, subset=subset, na.action=naa)
      } else {
          subset <- model$call$subset
!         rval <- model.frame(ff, data=data, subset=subset, na.action=I)
          oldmf <- model.frame(model)
          keep <- match(rownames(oldmf), rownames(rval))
          rval <- rval[keep, ]
--- 18,29 ----
      if (!na.expand){
          naa <- model$call$na.action
          subset <- model$call$subset
!         rval <- eval(call("model.frame",ff, data = data, subset = subset, 
!                       na.action = naa),enclos )
      } else {
          subset <- model$call$subset
!         rval <- eval(call("model.frame",ff, data = data, subset = subset, 
!                           na.action = I), enclos)
          oldmf <- model.frame(model)
          keep <- match(rownames(oldmf), rownames(rval))
          rval <- rval[keep, ]

---------END OF PATCH----------

--please do not edit the information below--

Version:
 platform = sparc-sun-solaris2.8
 arch = sparc
 os = solaris2.8
 system = sparc, solaris2.8
 status = 
 major = 1
 minor = 2.0
 year = 2000
 month = 12
 day = 15
 language = R

Search Path:
 .GlobalEnv, package:eda, 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] expand.model.frame() fails when subset is specified (PR#979)
gregory_r_warnes@groton.pfizer.com