[R] Too generic with S4 methods?

Ross Boylan ross at biostat.ucsf.edu
Thu Jun 2 23:44:09 CEST 2005


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          ross at biostat.ucsf.edu
Dept of Epidemiology and Biostatistics           fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840                     hm:  (415) 550-1062




More information about the R-help mailing list