timh at insightful.com
2008-Jan-05 01:05 UTC
[Rd] is(x, "parent") returns FALSE when class(x) is c("child", "parent") (PR#10549)
is() does not catch parent S3 classes:> library(splines) > temp <- bs(1:99, df=5) > class(temp)[1] "bs" "basis"> is(temp, "basis")[1] FALSE In contrast, is() does catch parent S4 classes:> library(copula) > norm.cop <- ellipCopula("normal", param = c(0.5, 0.6, 0.7),+ dim = 3, dispstr = "un")> is(norm.cop, "copula")[1] TRUE> class(norm.cop)[1] "normalCopula" --please do not edit the information below-- Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = major = 2 minor = 6.1 year = 2007 month = 11 day = 26 svn rev = 43537 language = R version.string = R version 2.6.1 (2007-11-26) Windows XP (build 2600) Service Pack 2.0 Locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 Search Path: .GlobalEnv, package:splines, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base
maechler at stat.math.ethz.ch
2008-Jan-05 10:00 UTC
[Rd] is(x, "parent") returns FALSE when class(x) is c("child", "parent") (PR#10549)
>>>>> "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? 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?'' (:-) [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) .....
Tim Hesterberg
2008-Jan-07 19:25 UTC
[Rd] is(x, "parent") returns FALSE when class(x) is c("child", "parent") (PR#10549)
In S-PLUS, is() does catch parent S3 classes. It does not require a setOldClass definition to do so. I would prefer that R work the same way, to make porting code easier. I use is() in S-PLUS for both S3 and S4 classes because it is faster than inherits(). I use inherits() only for testing a vector of classes, rather than a single class. To suggest that S3 has no class inheritance seems odd. We use inheritance of S3 classes all the time - "ordered" inheriting from "factor", many classes inheriting from "data.frame", etc. I see no problem in having inheritance without class definitions.>>>>>> "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: >... > >Yes, that's all correct, but where's the bug? > >S3 has *NO* class definitions, so how can there be class >inheritance? >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?'' (:-)
timh at insightful.com
2008-Jan-07 19:30 UTC
[Rd] is(x, "parent") returns FALSE when class(x) is c("child", "parent") (PR#10549)
In S-PLUS, is() does catch parent S3 classes. It does not require a setOldClass definition to do so. I would prefer that R work the same way, to make porting code easier. I use is() in S-PLUS for both S3 and S4 classes because it is faster than inherits(). I use inherits() only for testing a vector of classes, rather than a single class. To suggest that S3 has no class inheritance seems odd. We use inheritance of S3 classes all the time - "ordered" inheriting from "factor", many classes inheriting from "data.frame", etc. I see no problem in having inheritance without class definitions.>>>>>> "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: >... > >Yes, that's all correct, but where's the bug? > >S3 has *NO* class definitions, so how can there be class >inheritance? >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?'' (:-)