You and Martin are not really saying anything different, IMO. Martin I think is using "class inheritance" to mean inheritance inferred from class definitions, which S3 classes don't have. What inherits() does could technically be called "instance inheritance", that is, inheritance inferred from the object (the instance of the class) itself.
It's OK to stick to inherits() if you're dealing ONLY with S3 classes. To deal with a mixture of S3 and S4 classes and use is() for both, you need to declare the S3 classes, so that they have (minimal) definitions. For Tim's example, that would presumably be: setOldClass(c("bs", "basis")) which makes virtual S4 classes named "bs" and "basis". (It's not totally guaranteed, because people can, and sometimes do, use S3 classes in a way that can't map into simple class definitions via setOldClass, but as long as the S3 inheritance is consistent, a call to setOldClass will work.) John Tony Plate wrote: > [EMAIL PROTECTED] wrote: > >>>>>>> "TimH" == timh <[EMAIL PROTECTED]> >>>>>>> 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? >> >> > These types of statements make me really confused (and I suspect far > more than necessary). Isn't 'inherits()' an S3 function? (at least > it's not in package "methods", and it works with S3 classes, while 'is' > is in the "methods" package). > > The inherits documentation says: > Details: > > Many R objects have a 'class' attribute, a character vector giving > the names of the classes from which the object _inherits_. If the > object does not have a class attribute, it has an implicit class, > '"matrix"', '"array"' or the result of 'mode(x)' (except that > integer vectors have implicit class '"integer"'). (Functions > 'oldClass' and 'oldClass<-' get and set the attribute, which can > also be done directly.) > > But if S3 has no class definitions, and that fact precludes class > inheritance, how come the inherits() functions exists and works with S3 > "classes" and inherits() documentation talks about classes and inheritance? > > And it looks like 'inherits()' does what (I think) Tim Hesterberg is > looking for: > > > x <- structure(1, class=c("a", "ab", "abc")) > > is(x, "a") > [1] TRUE > > is(x, "ab") > [1] FALSE > > inherits(x, "a") > [1] TRUE > > inherits(x, "ab") > [1] TRUE > > > > > >> There's many reasons to go from S3 to S4, and the lack of class >> definitions in S3 is an important one... >> >> Now, still being curious: Are you implicitly saying that in S-plus, >> is() behaves differently, namely >> ``as if S3 classes would exist?'' (:-) >> >> > Is S-PLUS 7.0, I see the following behavior: > > > x <- structure(1, class=c("a", "ab")) > Warning in checkOldClass(c("a", "ab")): No formal definition of > old-style inheritance; consider setOldClass(c("a", > "ab")) > > inherits(x, "a") > [1] T > > inherits(x, "ab") > [1] T > > is(x, "a") > [1] T > > is(x, "ab") > [1] T > > > > Which would make it appear that in S-PLUS, for objects with S3 classes > the function "is" uses the definition of the concept "inherits" that > appears in the R documentation for the function "inherits" :-) (But, > apparently, S3 classes don't exist, so does that make R an imaginary > language except when one uses S4 classes? :-) > > -- Tony Plate > > >> [Of course, I understand what you mean, and I agree that >> normally, the S3 class attribute c("ch", "pr") means that "ch" >> is conceptually a child of "pr". >> >> However, there's at least one exception in R {which I have found a >> bit unfortunate, but never followed up}: >> >> > class(Sys.time()) >> [1] "POSIXt" "POSIXct" >> ] >> >> Regards, >> Martin >> >> TimH> Version: >> ..... >> TimH> version.string = R version 2.6.1 (2007-11-26) >> ..... >> >> ______________________________________________ >> R-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >> >> >> > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel