[R] setMethod confusion

Martin Maechler maechler at stat.math.ethz.ch
Wed Mar 15 09:53:36 CET 2006


>>>>> "Stephen" == Stephen Henderson <s.henderson at ucl.ac.uk>
>>>>>     on Tue, 14 Mar 2006 16:32:56 -0000 writes:

    Stephen> Hello I've checked through previous postings but
    Stephen> don't see a fully equivalent problem-just a few
    Stephen> hints.  I have been trying to set a new method for
    Stephen> the existing function "table" or
    Stephen> "as.data.frame.table" for my class "tfSites".
    Stephen> Taking out all the useful code and just returning
    Stephen> the input class I get the error

    >> setMethod("table", "tfSites", function(.Object) .Object)

    Stephen> Error in conformMethod(signature, mnames, fnames,
    Stephen> f) : In method for function "table": formal
    Stephen> arguments omitted in the method definition cannot
    Stephen> be in the signature (exclude = "tfSites")

 
    >> setMethod("as.data.frame.table", "tfSites",
    >> function(.Object) .Object )

    Stephen> Error in conformMethod(signature, mnames, fnames,
    Stephen> f) : In method for function "as.data.frame.table":
    Stephen> formal arguments omitted in the method definition
    Stephen> cannot be in the signature (x = "tfSites")

    Stephen> What does this mean? Is there something peculiar
    Stephen> about the table function? Is it because it takes
    Stephen> arguments beginning table(..., etc)

Yes.  Since table's  argument list starts with "..."
you cannot directly write S4 methods for it.

One could consider changing table's argument list to become 
  (x, ..., exclude = c(NA, NaN), dnn = list.names(...), deparse.level = 1) 
but that's not entirely trivial to do back compatibly, since
table() produces *named* dimnames from its arguments in "..."
and we'd want to make sure that this continues to work as now
even when the first argument is formally named 'x'.  E.g.,

 > X <- rpois(20, 1)
 > table(X)
 X
  0  1  2  3 
  7 10  2  1 
 > 

should continue to contain "X" as  names(dimnames(.)).

Of course this has now become a topic for R-devel rather
than R-help.

Martin Maechler,
ETH Zurich




More information about the R-help mailing list