Bug report: there is a problem with loglm (or some underlying code) when used with updating within a function. For example, this code works as expected, when used outside a function: ------------------------------------------------- library(MASS) cts<-c(25,13,99,45,128,78,151,153,173,171,49,62,1308,236,989,264,622,201,492,244,382,237,122,102,39,5,67,28,53,29,27,20,18,17,1,2,41,11,54,44,64,76,102,83,104,160,41,54,1232,321,1015,348,755,328,530,395,414,370,160,147,25,11,48,20,29,23,20,16,14,11,1,3) foo<-cbind(expand.grid(f1=factor(c("A","B")),f2=factor(11:16),f3=factor(c("S","N","E")),f4=factor(c("F","M"))),cts=cts) d0<-loglm(cts~f1+f2+f3+f4,data=foo) d1<-update(d0,.~.^2) ------------------------------------------------- but, unless d0 is visible outside the function, the same code does not work as expected when within a function: ------------------------------------------------- rm(list=ls()) library(MASS) tester<-function(){ cts<-c(25,13,99,45,128,78,151,153,173,171,49,62,1308,236,989,264,622,201,492,244,382,237,122,102,39,5,67,28,53,29,27,20,18,17,1,2,41,11,54,44,64,76,102,83,104,160,41,54,1232,321,1015,348,755,328,530,395,414,370,160,147,25,11,48,20,29,23,20,16,14,11,1,3) foo<-cbind(expand.grid(f1=factor(c("A","B")),f2=factor(11:16),f3=factor(c("S","N","E")),f4=factor(c("F","M"))),cts=cts) d0<-loglm(cts~f1+f2+f3+f4,data=foo) d1<-update(d0,.~.^2) } tester() ------------------------------------------------- results in the message: Error: Object "foo" not found David. --------------------------------------------------------------------- David Wooff, Director, Statistics and Mathematics Consultancy Unit, Department of Mathematical Sciences, University of Durham. Science Laboratories, South Road, Durham, DH1 3LE, UK. Tel. 0191 374 4531, Fax 0191 374 7388. --------------------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> From: D.A.Wooff@durham.ac.uk > Date: Thu, 18 Feb 1999 18:09:33 +0100 > To: r-devel@stat.math.ethz.ch > Subject: [R] possible bug in loglm (PR#122) > CC: R-bugs@biostat.ku.dk > X-Loop: R-bugs@biostat.ku.dk > > Bug report: there is a problem with loglm (or some underlying code) > when used with updating within a function. For example, this code > works as expected, when used outside a function:Well, loglm is not part of R per se, so I was a little surprised to see this going to R-bugs. The answer is along the lines of `yes, we know, this is part of the limitations of update and NextMethod', and this occurs in S-PLUS too, and for lots of other applications of update. You could alter update.loglm to be update.loglm <- function (object, formula., ...) { setdiff <- function(x, y) if (length(x) == 0 || length(y) == 0) x else x[match(x, y, 0) == 0] if (is.null(call <- object$call)) stop("object has no call component. Updating not possible") if (fix <- !missing(formula.)) { object$formula <- denumerate(object$formula) formula. <- denumerate(formula.) call$formula <- update.formula(formula(object), formula.) } extras <- match.call(expand.dots = FALSE)$... if (length(extras) > 0) { existing <- !is.na(match(names(extras), names(call))) ## do these individually to allow NULL to remove entries. for (a in names(extras)[existing]) call[[a]] <- extras[[a]] if (any(!existing)) { call <- c(as.list(call), extras[!existing]) call <- as.call(call) } } result <- eval(call, sys.frame(sys.parent())) if (fix) { form <- renumerate(result$formula) result$call$formula <- unclass(result$formula <- form) } result } that is to remove the NextMethod call. But this sort of thing is quite common, and the usual workaround is to make sure that the dataframe is visible. -- Brian D. Ripley, ripley@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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._