On Mon, 21 Jun 2010, Henrik Bengtsson wrote:

On Mon, Jun 21, 2010 at 4:23 PM, Gábor Csárdi <csa...@rmki.kfki.hu> wrote:
On Mon, Jun 21, 2010 at 4:17 PM, Duncan Murdoch
<murdoch.dun...@gmail.com> wrote:
[...]
The requirement is that the methods need to have signatures that contain all
the arguments of the generic.  If the generic includes ..., then the methods
can add other arguments, too.  So with the generic for plot() as you show
above, any plot method is required to have x and y as the first two
arguments, and ... as an argument, but they can have other args too.

This makes sense, and it is actually great! Thanks a lot for the explanation.

FYI, the most "generic" way you can write a generic function is:

foo <- function(...) UseMethod("foo");


This is only the "most generic" way if you want dispatch on the first argument. 
 You can have dispatch on a different argument, and that requires you to specify 
arguments to the generic function.

For example, I have written quite a few functions of the form
   foo <- function(formula, data, ...) UseMethod("foo", data)


        -thomas

Thomas Lumley                   Assoc. Professor, Biostatistics
tlum...@u.washington.edu        University of Washington, Seattle
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to