Skip to content
Prev 51724 / 63424 Next

unary class union of an S3 class

On Sat, Mar 19, 2016 at 12:10 AM, Herv? Pag?s <hpages at fredhutch.org> wrote:

            
You can only do that with setClassUnion(). But the new classes should use
setIs() to inherit from the union. So it's:

setClassUnion("ArrayLike", "array")
setClass("MyArrayLike")
setIs("MyArrayLike", "ArrayLike")
Containing does two things: establishes the is() relationship and adds
slots to the class. These slots are comprised of the slots of the contained
class, and as a special case the "array" class and other native types
confer a data part that comes from the prototype of the class. The "array"
class has a double vector with a dim attribute as its prototype. That is
all well understood. What is surprising is that "ArrayLike" has the same
prototype as "array". That happens via setIs(doComplete=TRUE), called by
setClassUnion(). When a class gains its first non-virtual child, the parent
assumes the prototype of its child.  I'm not sure why, but the logic is
very explicit and I've come to just accept it as a "feature". I ran into
this some months ago when defining my own ArrayLike when working on a very
similar package to the one you are developing ;)