Skip to content
Prev 55258 / 63424 Next

Creating S3 methods for S4 classes (coming from r-package-devel)

On Thu, May 24, 2018 at 6:20 PM, Michael Lawrence <lawrence.michael at gene.com
I was refering to the recommendations in ?Methods_for_S3 (
https://stat.ethz.ch/R-manual/R-devel/library/methods/html/Methods_for_S3.html).
:

"Two possible mechanisms for implementing a method corresponding to an S4
class, there are two possibilities are to register it as an S3 method with
the S4 class name or to define and set an S4 method, which will have the
side effect of creating an S4 generic version of this function.

For most situations either works, but the recommended approach is to do
both:"

The reasoning is described there as well, and I have no reason to believe
that information is not up to date. I can get away with defining an S3
generic, but this stops being useful when using superclasses for reasons
mentioned in the documentation.

I
I would personally prefer to use dispatching that's tailored to the type of
class I work with, as that seems more consistent. But I agree we should
avoid defining generics for the same function in different packages, hence
my proposal about stats4.