[Rd] S4 method implementation for S3 class

Iñaki Úcar i.ucar86 at gmail.com
Sat Sep 23 18:17:22 CEST 2017


> There is formally no such thing as an S3 class. Just S3 objects with a
> class attribute. You could extend a base class with an S4 class, like
> setClass("IntegerWithUnits", slots=c(units="Units"),
> contains="integer"). Sure, that's a disruptive change, but it would be
> in the right direction.
>
> Extending base classes is always a risky proposition, as you've
> discovered. Ideally you would override every transformation in order
> to adjust or carry over the representation accordingly. The problem is
> that there's a huge amount of transformations available for base
> classes, mostly not encapsulated by generics.
>
> Other possibilities include:
> - Convincing someone to make %*% an internal S3 generic
> - Promoting %*% to an R-level S3 generic, which would only work with
> code that sees your namespace
>
> Hopefully others have better ideas,
> Michael

Thanks for your kind help and suggestions, Michael. I think I'll take
the last option as a workaround, at least until I evaluate the
advantages and drawbacks of a complete redesign.

Iñaki



More information about the R-devel mailing list