Originally I made a function yearStop that took an argument "object". I made a generic, but later changed the argument to "x". R keeps resurrecting the old definition. Could anyone explain what is going on, or how to fix it? Note particularly the end of the transcript below: I remove the generic, verify that the symbol is undefined, make a new function, and then make a generic. But the generic does not use the argument of the new function definition. <quote>> args(yearStop)function (obj) NULL> yearStop <- function(x) x at yearStop > args(yearStop)function (x) NULL> setGeneric("yearStop")[1] "yearStop"> args(yearStop)function (obj) NULL> removeGeneric("yearStop")[1] TRUE> args(yearStop)Error in args(yearStop) : object "yearStop" not found> yearStop <- function(x) x at yearStop > setGeneric("yearStop")[1] "yearStop"> args(yearStop)function (obj) NULL </quote> R 2.7.1. I originally read the definitions in from a file with ^c^l in ESS; however, I typed the commands above by hand. Thanks. Ross Boylan
Ross Boylan wrote:> Originally I made a function yearStop that took an argument "object". I > made a generic, but later changed the argument to "x". R keeps > resurrecting the old definition. Could anyone explain what is going on, > or how to fix it? Note particularly the end of the transcript below: I > remove the generic, verify that the symbol is undefined, make a new > function, and then make a generic. But the generic does not use the > argument of the new function definition. > > <quote> >> args(yearStop) > function (obj) > NULL >> yearStop <- function(x) x at yearStop >> args(yearStop) > function (x) > NULL >> setGeneric("yearStop") > [1] "yearStop" >> args(yearStop) > function (obj) > NULL >> removeGeneric("yearStop") > [1] TRUE >> args(yearStop) > Error in args(yearStop) : object "yearStop" not found >> yearStop <- function(x) x at yearStop >> setGeneric("yearStop") > [1] "yearStop" >> args(yearStop) > function (obj) > NULL > </quote> > > R 2.7.1. I originally read the definitions in from a file with ^c^l inI don't see this behavior in R-2.9.2, or in the release candidate. Martin> ESS; however, I typed the commands above by hand. > > Thanks. > Ross Boylan > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793
Here's a self-contained example of the problem:> foo <- function(obj) {return(3);} > setGeneric("foo")[1] "foo"> removeGeneric("foo")[1] TRUE> foo <- function(x) {return(4);} > args(foo)function (x) NULL> setGeneric("foo")[1] "foo"> args(foo)function (obj) NULL R 2.7.1. I get the same behavior whether or not I use ESS. The reason this is more than a theoretical problem:> setMethod("foo", signature(x="numeric"), function(x) {return(x+4);})Error in match.call(fun, fcall) : unused argument(s) (x = "numeric") Ross