Yes, you're correct. From the Green book ("Programming with Data"):(p.323) "Strictly speaking, the [specific] method supplied [for a generic] must have the exact same formal argument list as the generic ... However, if you do supply a function with different arguments, setMethod will construct a valid method that calls the function you supplied, passing down all the arguments of the generic." -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Ross Boylan > Sent: Thursday, June 02, 2005 2:44 PM > To: r-help > Subject: [R] Too generic with S4 methods? > > I tried the following (relevant excerpt only) > setMethod("likelihood", > signature(spec="Specification", covs="vector", > states="vector"), > function(spec, covs, states) { > #### > setMethod("likelihood", > signature(model="Model", path="matrix"), > function(model, path) { > > This fails with the message > arguments in definition changed from (spec) to (object) > Error in match.call(fun, fcall) : unused argument(s) (model ...) > > I'll note in passing that it would be helpful to have a line > number for > the error, and that the error didn't mean much to me. > > After study, my guess is that generics are not supposed to work this > way. All the definitions need to have the same named arguments > (exceptions: some can be "missing", and ... is allowed). So the error > above is a complaint that my second signature uses different names (or > is it different classes?). And the "unused argument" is triggered by > the fact that the original signature had 3 args named spec, covs, and > states, and the new signature has none of them. Is that about right? > > It looks as if I might get away by not naming the arguments, so the > first signature could be signature("Specification", "vector", > "vector") > and the 2nd signature("Model", "matrix", "missing"). > > Among other problems, the lack of identifiers makes the > semantics of the > signature obscure in this case. > > Basically, would it be advisable to use different generic > names for the > two functions listed above? > -- > Ross Boylan wk: (415) 502-4031 > 530 Parnassus Avenue (Library) rm 115-4 [EMAIL PROTECTED] > Dept of Epidemiology and Biostatistics fax: (415) 476-9856 > University of California, San Francisco > San Francisco, CA 94143-0840 hm: (415) 550-1062 > > ______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
