Skip to content
Prev 82353 / 398513 Next

Dots argument in apply method

Why does simply

setMethod("apply",
           signature(X = "myClass",
                     MARGIN = "numeric",
                     FUN = "function"),
           function(X, MARGIN, FUN, ...) .apply.myClass(X, MARGIN, FUN, ...))

not do what you want?  It works for me in your example, e.g.
gives exactly the same answer as your complicated solution.

I do wonder if you have misunderstood what '...' does.


I also wonder why you chose to overload a basic R function as an S4 
generic like this.  If you think that thereby existing calls to apply() 
will go via your S4 methods then I fear you have overlooked the effects of 
namespaces.

A simpler example

setClass("myClass", representation(tt="numeric"))
setMethod("lapply", signature(X="myClass"), function(X, FUN, ...) FUN(X at tt))
myObj <- new("myClass", tt=1:10)
[1] 55
list()

since sapply is calling base::lapply, not the lapply S4 generic.
On Wed, 7 Dec 2005, Christophe Pouzat wrote: