gregory_r_warnes@groton.pfizer.com
2001-Jun-14 18:15 UTC
[Rd] expand.model.frame() fails when subset is specified (PR#979)
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2001-Jun-14 18:54 UTC
[Rd] expand.model.frame() fails when subset is specified (PR#979)
gregory_r_warnes@groton.pfizer.com writes:> 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 >Thanks. This is also present in the current pre-1.3.0. Your patch looks correct, but I wonder if the default for "enclos" should not be environment(formula(model)) rather than parent.frame() as it is now? (And wouldn't it be better named "envir"?) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._