From maechler at stat.math.ethz.ch  Sat Jan  5 22:26:42 2008
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Sat, 5 Jan 2008 22:26:42 +0100
Subject: [Rd] is(x, "parent") returns FALSE when class(x) is c("child",
	"parent") (PR#10549)
In-Reply-To: <477FD672.50906@acm.org>
References: <20080105100015.230A52834847@mail.pubhealth.ku.dk>
	<477FD672.50906@acm.org>
Message-ID: <18303.62994.578842.888135@ada-stat.math.ethz.ch>

>>>>> "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 


[Rd] is(x, "parent") returns FALSE when class(x) is c("child", "parent") (PR#10549)
Martin Maechler