[Rd] S4 classes that extend S3 classes
jmc at r-project.org
Mon Jul 28 22:13:07 CEST 2008
Up to now, writing an S4 class that extends an S3 class (using
contains= in the call to setClass) has been discouraged for two main
1. You can't say anything formal about S3 classes, so validating
objects, having formal slots for their properties, etc. are not
2. In any case, the S3 class, which may have multiple strings in the
class attribute, was not available in objects from the S4 class; so,
among other problems, S3 method dispatch would not work for such a class.
The first problem is fairly intrinsic and remains a reason to hesitate.
But a recent change to the 2.8.0 development version takes some steps to
reduce the second problem.
The mechanism is to include the S3 class of objects as a special slot in
any class that extends "oldClass"; therefore, any S3 class registered by
calling setOldClass(), and any S4 class that extends such a class, will
have the underlying S3 class available. S3 method dispatch and the
inherits() function make use of this information in the latest version
(revision r46128 of July 27, with a bug fix r46136 July 28).
So if you can live with the limitations of the first point and would
like to experiment with extending an S3 class, you're invited to try.
Note that the S3 classes _must_ be registered via setOldClass() for
extensions to work.
See ?Classes, ?setOldClass and ?S3Class for details.
More information about the R-devel