Skip to content
Prev 36655 / 63424 Next

Validity glitch when contains="matrix"

Re: the validity bug.  It's just as your example suggests:  the 
inherited initialize() method for "matrix" fails to call validObject(). 
  Should be easy to fix.  (Although it points out that the code should 
perhaps be reorganized so the initialize() method is not responsible for 
checking validity.)


Re: your other question:
On 5/6/10 4:09 AM, Martin Maechler wrote:
<snip>
Either is possible, but if you really want your new objects to inherit 
the properties of a matrix, your initial idea of contains="matrix" is 
the natural choice for 2) (once the bug is fixed, but even before for 
most purposes). The choice is to inherit from matrix or have matrix as a 
slot (what Smalltalk called "is a" versus "has a").

The choice is as always whether you want to inherit all the methods and 
then override the ones that DON'T make sense, or put the matrix in a 
slot and write all the methods that DO make sense.

Neither choice fits all examples but "matrix" is special, because R 
treats them in a special (perhaps "weird" would apply) way:  they are 
not a class (not even an S3 class) but much code recognizes them 
internally, meaning you inherit a great deal of stuff.

If your new class of objects are supposed to act like matrices most of 
the time, the contains= version may require a lot less programming. On 
the other hand, if you planned to store the data in a non-standard way 
(as the Matrix package does) then you really don't want to inherit the 
standard methods because any you failed to override could be disastrous.