Skip to content
Prev 21839 / 63424 Next

setMethod("c") [was: setMethod("Summary")]

It's all very well to go on about efficiency, but the purpose of 
statistical computing is insight into data, not saving CPU cycles (to 
paraphrase Dick Hamming).

S3 methods do some things fine; other tasks need more flexibility.  One 
should ask what's important in a particular application and try to find 
tools that match the needs well.

Now, the c() function.  This has been discussed in various forms (and 
languages) for some time.  As I remember and as far as I know, the only 
really general way to ensure dispatch on _any_ applicable argument is to 
turn the computation into a pair-wise one and define the methods (NOT S3 
methods) for the two arguments of the pairwise function.

I won't try to reproduce the details off the top of my head (if I locate 
a reference I'll pass it on), but very roughly the idea is to say 
something like

cWithMethods <- function(x, ...) {
   if(nargs()<3)
      cPair(x,...)
    else
      cPair(x, cWithMethods(...))
}

and then write methods for cPair().

John
Robin Hankin wrote: