[Rd] is(x, "parent") returns FALSE when class(x) is c("child", "parent") (PR#10549)
Martin Maechler
maechler at stat.math.ethz.ch
Sat Jan 5 22:26:42 CET 2008
>>>>> "TP" == Tony Plate <tplate at acm.org>
>>>>> on Sat, 05 Jan 2008 12:11:46 -0700 writes:
TP> maechler at stat.math.ethz.ch wrote:
>>>>>>> "TimH" == timh <timh at insightful.com>
>>>>>>> on Sat, 5 Jan 2008 02:05:08 +0100 (CET) writes:
>>>>>>>
>>
TimH> is() does not catch parent S3 classes:
>>
>> >> library(splines)
>> >> temp <- bs(1:99, df=5)
>> >> class(temp)
TimH> [1] "bs" "basis"
>> >> is(temp, "basis")
TimH> [1] FALSE
>>
TimH> In contrast, is() does catch parent S4 classes:
>> >> library(copula)
>> >> norm.cop <- ellipCopula("normal", param = c(0.5, 0.6, 0.7),
TimH> + dim = 3, dispstr = "un")
>> >> is(norm.cop, "copula")
TimH> [1] TRUE
>> >> class(norm.cop)
TimH> [1] "normalCopula"
>>
>> Yes, that's all correct, but where's the bug?
>>
>> S3 has *NO* class definitions, so how can there be class
>> inheritance?
TP> These types of statements make me really confused (and I suspect far
TP> more than necessary). Isn't 'inherits()' an S3 function? (at least
TP> it's not in package "methods", and it works with S3 classes, while 'is'
TP> is in the "methods" package).
John already kindly answered, but yes, indeed, my statements
must have been somewhat confusing.
Prompted by Tim's ("child", "parent"),
I was talking about *class* inheritance (which does not exist
for S3) but with his question/remark/bug report about
is(<obj>, <class>)
Tim was really concerned with *objects* inheriting from classes
and Tony's answer about inherits() vs is() was well appropriate.
When I was talking about class inheritance,
I was talking about "parent child relationships" between
classes, where "the answer" is extends(), not is().
E.g.
> library(Matrix)
> extends("dgCMatrix", "CsparseMatrix")
[1] TRUE
> extends("CsparseMatrix", "sparseMatrix")
[1] TRUE
> extends("sparseMatrix", "Matrix")
[1] TRUE
And last year, I've finished a small CRAN package, called 'classGraph',
which nicely visualizes such class inheritance by drawing
graphs (using the bioconductor packages 'Rgraphviz' and 'graph'):
library(Matrix)
library(classGraph)
cg2. <- class2Graph("dgCMatrix", fullNames=FALSE)
plot(cg2.)
then produces the attached plot which *is* all about class
inheritance, only present in S4, but, again, I apologize for
confusing you, since Tim really needed the "class instance" or
"object -> class" inheritance.
Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dgCMatrix-class-graph.png
Type: image/png
Size: 4873 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20080105/ce13a874/attachment.png
More information about the R-devel
mailing list