Re: [R] setAs vs setIs

From: Martin Maechler <>
Date: Mon, 17 Mar 2008 10:33:39 +0100

>>>>> "CG" == Christophe Genolini <> >>>>> on Mon, 17 Mar 2008 09:42:09 +0100 writes:

    CG> I works, great !
    CG> So using your code, we can define 'as','as<-' and 'is' with setIt. Is 
    CG> there still any interest using setAs ?

Well, ?setIs contains

>> This function establishes an inheritance relation
>> between two classes, by some means other than having one
>> class contain the other. It should _not_ be used for
>> ordinary relationships: either include the second class in
>> the 'contains=' argument to 'setClass' if the class is
>> contained in the usual way, or consider 'setClassUnion' to
>> define a virtual class that is extended by several ordinary
>> classes. A call to 'setIs' makes sense, for example, if one
>> class ought to be automatically convertible into a second
>> class, but they have different representations, so that the
>> conversion must be done by an explicit computation, not just
>> be inheriting slots, for example. In this case, you will
>> typically need to provide both a 'coerce=' and 'replace='
>> argument to 'setIs'.

which for me has been entailing that you should use setIs() only rarely but rather

use setClass(..., contains = ....)
and setAs(.....)

much more frequently. That may well depend on the kind of your classes of course.
For the 'Matrix' package at least, our experience and use testing has resulted in almost no use of setIs() but rather hierarchical class definitions, i.e., the above setClass( ..., contains=), and many setAs(...).

Martin Maechler, ETH Zurich mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 17 Mar 2008 - 09:37:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 17 Mar 2008 - 10:30:22 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive