[Rd] setMethod("Summary")

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Sep 5 11:21:42 CEST 2006


On Tue, 5 Sep 2006, Martin Maechler wrote:

> >>>>> "Robin" == Robin Hankin <r.hankin at 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 at 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




More information about the R-devel mailing list