PS: I've committed a workaround that seems to fix the symptoms ( rev. 47020/1 for 2.9.0 and 2.8-patched), but it would be good to fix the real problem.
John Chambers wrote: > There were a bunch of red herrings in your example, but the end result > is at least as weird. > > Near as I can figure, it's a bug in the evaluator when assigning a local > function call object that is then modified. I'll look a bit at the > code, but someone more expert in the innards of the evaluator might be > needed. > > All you need is to do one of the setGeneric() calls. The clue is to > look at a utility function in the methods package that constructs a > function call to .Method. > > The bug is that after the first call, the definition of the utility > function has been modified to contain the results of the call. So all > the arguments from successive calls accumulate! > > The minimal example is below. Look at the "call <-" line the second > time the function .makeDotsCall is printed: it has the arguments from > order() in the expression on the right hand side. > > At a guess, for some reason object "call" isn't marked correctly in the > NAMED() field, so the evaluation of, e.g., call$na.last <- > as.name("na.last") overwrites the expression in the definition of > .makeDotsCall. > > John > > > methods:::.makeDotsCall > function (formals) > { > call <- quote(.Method(...)) > if (length(formals) > 1) { > idots <- match("...", formals) > for (what in formals[-idots]) { > eval(substitute(call$NAME <- as.name(WHAT), list(NAME = > as.name(what), > WHAT = what))) > } > } > call > } > <environment: namespace:methods> > > > setGeneric("order", signature="...", > + function (..., na.last=TRUE, decreasing=FALSE) > + standardGeneric("order")) > Creating a generic for "order" in package ".GlobalEnv" > (the supplied definition differs from and overrides the implicit > generic in package "base": Signatures differ: (...), (na.last, decreasing)) > [1] "order" > > > methods:::.makeDotsCall > function (formals) > { > call <- quote(.Method(..., na.last = na.last, decreasing = decreasing)) > > > Michael Lawrence wrote: > >> There seems to be a bug arising when using multiple S4 generics with "..." >> as the signature. >> >> The following code works as expected: >> >> ############################################################## >> >> >> >>> setGeneric("rbind", function(..., deparse.level=1) >>> >>> >> standardGeneric("rbind"), >> + signature = "...") >> Creating a generic for "rbind" in package ".GlobalEnv" >> (the supplied definition differs from and overrides the implicit generic >> in package "base": Signatures differ: (...), (deparse.level)) >> [1] "rbind" >> >> >>> rbind(1) >>> >>> >> [,1] >> [1,] 1 >> >> >>> rbind >>> >>> >> standardGeneric for "rbind" defined from package ".GlobalEnv" >> >> function (..., deparse.level = 1) >> standardGeneric("rbind") >> <environment: 0x83862f4> >> Methods may be defined for arguments: ... >> Use showMethods("rbind") for currently available ones. >> >> >>> removeGeneric("rbind") >>> >>> >> [1] TRUE >> >> >>> rbind >>> >>> >> function (..., deparse.level = 1) >> .Internal(rbind(deparse.level, ...)) >> <environment: namespace:base> >> >> >>> setGeneric("order", signature="...", >>> >>> >> + function (..., na.last=TRUE, decreasing=FALSE) >> + standardGeneric("order")) >> Creating a generic for "order" in package ".GlobalEnv" >> (the supplied definition differs from and overrides the implicit generic >> in package "base": Signatures differ: (...), (na.last, decreasing)) >> [1] "order" >> >> >>> rbind(1) >>> >>> >> [,1] >> [1,] 1 >> >> >>> setGeneric("rbind", function(..., deparse.level=1) >>> >>> >> standardGeneric("rbind"), >> + signature = "...") >> Creating a generic for "rbind" in package ".GlobalEnv" >> (the supplied definition differs from and overrides the implicit generic >> in package "base": Signatures differ: (...), (deparse.level)) >> [1] "rbind" >> >> >>> rbind(1) >>> >>> >> [,1] >> [1,] 1 >> >> ########################################################## >> >> That is, rbind(1) always returns the expected result. The rbind() generic is >> set, then removed, the order() generic is set, and the rbind() generic is >> set again. No problems. >> >> But in a new session, this code breaks, where the rbind() generic is not set >> before the order() generic: >> >> ######################################################## >> >> >> >>> setGeneric("order", signature="...", >>> >>> >> + function (..., na.last=TRUE, decreasing=FALSE) >> + standardGeneric("order")) >> Creating a generic for "order" in package ".GlobalEnv" >> (the supplied definition differs from and overrides the implicit generic >> in package "base": Signatures differ: (...), (na.last, decreasing)) >> [1] "order" >> >> >>> rbind(1) >>> >>> >> [,1] >> [1,] 1 >> >> >>> setGeneric("rbind", function(..., deparse.level=1) >>> >>> >> standardGeneric("rbind"), >> + signature = "...") >> Creating a generic for "rbind" in package ".GlobalEnv" >> (the supplied definition differs from and overrides the implicit generic >> in package "base": Signatures differ: (...), (deparse.level)) >> [1] "rbind" >> >> >>> rbind(1) >>> >>> >> Error in .Method(..., na.last = na.last, decreasing = decreasing, >> deparse.level = deparse.level) : >> object "na.last" not found >> >> ############################################################## >> >> It looks like something is trying to send the parameters of order() to an >> rbind() method. Weird.. >> >> Thanks, >> Michael >> >> >> >>> sessionInfo() >>> >>> >> R version 2.9.0 Under development (unstable) (--) >> i686-pc-linux-gnu >> >> locale: >> C >> >> attached base packages: >> [1] stats graphics grDevices utils datasets methods base >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >> >> >> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel