Skip to content
Prev 10248 / 63424 Next

s4 methods and base

Paul Gilbert wrote:
......................
No, I'm not using it loosely, but I am using it as it's used for S4
classes.

"contains" is an argument in defining a class via setClass().  Its
meaning is essentially the mathematical one, as in "Set B contains set
A."  If we think of a class as corresponding to a set of slots, that is,
a set of (name, class) pairs, then "class B contains class A" says that
the set of slots for B contains that for A.

"extends" is a more general concept in the S class system.  See
Programming with Data for details and examples, but the essential
meaning of "class B extends class A"  is that any instance of B can be
used when an instance of A is needed.  As I said, "contains" is the most
common but not the only way to create an "extends" relation.

"inherits" is an S3 concept defined in Statistical Models in S.  In
practice, it says ONLY that "A" appears in the class attribute for a
particular object, and not necessarily as the first string.  One of the
problems with an informal, instance-based, system is that there is no
way to verify what if anything inheritance implies.
If we rephrase the question as "can an S4 class have objects from S3
classes as slots", the answer is yes, but you should "register" the S3
classes to the formal class system, by calling setOldClass (see the
online documentation).  That's what we did for the base package's
classes, as discussed re John Marslan's mail. So, e.g.,
  setOldClass(c("ordered", "factor"))
to register the S3 class "ordered" with its inheritance from "factor".

Registration isn't enforced yet, but I would like to do so, in order to
require that all the slots in a class definition correspond to defined
classes.
There are ways to provide a degree of "automatic" class extension for
features that are midway between universal necessities and purely
specialized techniques.  I'm not quite convinced this is a sufficiently
desirable mechanism, but in any case a way to start would be a nice
simple implementation, e.g., as a class with corresponding methods, say,
to extract or assign a "note"; i.e., for generic functions `note(object,
name)' and `note(object, name) <- value'.

John