Re: [Rd] setMethod("Summary")

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue 05 Sep 2006 - 09:21:42 GMT

On Tue, 5 Sep 2006, Martin Maechler wrote:

> >>>>> "Robin" == Robin Hankin <r.hankin@noc.soton.ac.uk>
> >>>>> on Tue, 5 Sep 2006 08:58:23 +0100 writes:
>
> Robin> Dear Franklin
> Robin> thank you for this.
>
> yes, and he *did* send it already last week.
>
> Robin> Your suggestion works.
>
> and continues to do so in R-devel aka "R-2.4.0 alpha" (as of today?)
>
> Robin> But now I'm confused because I'm not sure how
> Robin> the
> Robin> setGeneric() call actually helps.
>
> Robin, I think you got confused because you are mixing S3 and S4
> ("max.brob" is S3).
>
> You should (typically) not define S3 methods for S4 classes,
> and you should definitely not do it in this case where Franklin
> has shown the correct S4 way.
> (and for my taste you should also not do it for the "Logic" case
> in that other thread last week: It does not bring you anything and is
> ugly for me, from the point of view of S4.)

But it *does* bring you something, efficiency. If all you want to do is to stop the default method dispatching, using an S3 method can be lot more efficient than an S4 method. In the example which has been omitted here, making 'max' S4 generic adds an overhead to *all* calls to max() in the rest of the session. Adding a max.brob method costs nothing at all (max is already S3 generic and efficiently so).

People tend to forget how expensive it is to mess with R basics, which applies both to taking them over as S4 generics and making them S3 generic via UseMethod.

If a function/operator has already been made S4 generic or is not written for efficiency then it is reasonable to add an S4 method. But otherwise, please think carefully about the impact on other people's code.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue Sep 05 19:24:58 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 06 Sep 2006 - 11:39:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.