[R] Dots argument in apply method

Christophe Pouzat christophe.pouzat at univ-paris5.fr
Wed Dec 7 15:56:21 CET 2005

Dear Prof. Ripley,

Thanks for the clarification. 

Prof Brian Ripley wrote:

> 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.
>> apply(myObj, 2, sum, groups=myObj at Data$label)
> gives exactly the same answer as your complicated solution.
> I do wonder if you have misunderstood what '...' does.

I hope not (entirely).
I got a bizarre bug yesterday while working on that method/function 
issue which lead me (wrongly, because of a too quick diagnostic 
probably) to think there was a problem with the way the "..." was passed 
from one function to the next. That explains the complicated construct 
of my previous e-mail.
Your solution works (of course) and is definitely simpler (!).

> 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.
No, I just want the user to be able to call "apply" with myClass objects 
without having to bother with the internal structure of these objects 
(which is slightly more complicated in my "real" case than on the 
example I sent).

Thanks again,


A Master Carpenter has many tools and is expert with most of them.If you
only know how to use a hammer, every problem starts to look like a nail.
Stay away from that trap.
Richard B Johnson.

Christophe Pouzat
Laboratoire de Physiologie Cerebrale
UFR biomedicale de l'Universite Paris V
45, rue des Saints Peres
75006 PARIS

tel: +33 (0)1 42 86 38 28
fax: +33 (0)1 42 86 38 30
web: www.biomedicale.univ-paris5.fr/physcerv/C_Pouzat.html

More information about the R-help mailing list