Simple Class Extensions

A class C2 is defined to be a simple extension of a class C1 if the two classes are related by a simple setIs call:
  setIs(C2, C1)
Simple extensions happen in two ways:

  1. Implicitly, by C1 being included in the representation of C2, in which case no explicit call to setIs is needed;

  2. Explicitly, by a call to setIs, in which case C1 must either be a virtual class or included in C2 (in the sense of both having the same definition for all the slots of C1).

In the current version of R (1.5.0 and later), simple extensions are used in formal method dispatch without transforming the actual argument. That is, if a method exists corresponding to class C1 for some argument, and the actual argument has class C2, then the method can be selected. If it is, the method will be called with an untransformed argument (still class C2, not the defined class).

We are considering applying the same convention to slot assignments. Suppose a slot is assigned, say

  z@type <- x
If the slot was defined to have class C1 and x has class C2, the assignment would succeed and x would be stored in the slot, untransformed.

The same rule would apply to named arguments supplied to the function new, assuming the class had no special initialize method defined.

There are a few details to note:


John Chambers<jmc@research.bell-labs.com>
Last modified: Thu Mar 7 14:50:08 EST 2002