Could someone explain the following behavior to me, which I find inconsistent and confusing:> inherits(1L, "integer")[1] TRUE **as expected. S3 class**> inherits(1L, class_integer)[1] TRUE ** as expected. S7 base class**> inherits(1.0, "double")[1] FALSE ** There is no "double" class in S3> inherits(1.0, "numeric")[1] TRUE ** doubles are S3 class "numeric". This is (sort of) documented** BUT ...> inherits(1.0, class_double)[1] FALSE ** because there is no S3 class "double" ?? **> inherits(1.0, class_numeric)Error in inherits(1.2, class_numeric) : 'what' must be a character vector or an object with a nameOfClass() method **class_numeric is an S7 union, not an S7 base class ?** So if 1.0 is not class_double, what base class is it? And how should I test for the class of a non-integer numeric? And what is class_double then? My apologies if this is obvious, but as I said, I find this confusing. Best, Bert [[alternative HTML version deleted]]
Hello, I know nothing about S7 classes but here are two notes. (Inline) ?s 00:35 de 05/01/2026, Bert Gunter escreveu:> Could someone explain the following behavior to me, which I find > inconsistent and confusing: > >> inherits(1L, "integer") > [1] TRUE **as expected. S3 class** >> inherits(1L, class_integer) > [1] TRUE ** as expected. S7 base class** > >> inherits(1.0, "double") > [1] FALSE ** There is no "double" class in S3 >> inherits(1.0, "numeric") > [1] TRUE ** doubles are S3 class "numeric". This is (sort of) documented** > > BUT ... >> inherits(1.0, class_double) > [1] FALSE ** because there is no S3 class "double" ?? **I don't believe this is the reason why it's giving an error. The first example in vignette("classes-objects", package = "s7") defines an new class Range with two properties, start and end, both of class class_double.> >> inherits(1.0, class_numeric) > Error in inherits(1.2, class_numeric) : > 'what' must be a character vector or an object with a nameOfClass() method > **class_numeric is an S7 union, not an S7 base class ?**Apparently, 1.0 has no S7 class (?) library(S7) S7_class(1.0) #> NULL x <- 1.0 S7_class(x) #> NULL nameOfClass(x) #> NULL This is all I can say, I have no explanation nor solution. Hope this helps, Rui Barradas> > So if 1.0 is not class_double, what base class is it? And how should I test > for the class of a non-integer numeric? And what is class_double then? > > My apologies if this is obvious, but as I said, I find this confusing. > > Best, > Bert > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On 2026-01-04 7:35 p.m., Bert Gunter wrote:> Could someone explain the following behavior to me, which I find > inconsistent and confusing: > >> inherits(1L, "integer") > [1] TRUE **as expected. S3 class** >> inherits(1L, class_integer) > [1] TRUE ** as expected. S7 base class** > >>> [1] FALSE ** There is no "double" class in S3 >> inherits(1.0, "numeric") > [1] TRUE ** doubles are S3 class "numeric". This is (sort of) documented** > > BUT ... >> inherits(1.0, class_double) > [1] FALSE ** because there is no S3 class "double" ?? ** > >> inherits(1.0, class_numeric) > Error in inherits(1.2, class_numeric) : > 'what' must be a character vector or an object with a nameOfClass() method > **class_numeric is an S7 union, not an S7 base class ?** > > So if 1.0 is not class_double, what base class is it? And how should I test > for the class of a non-integer numeric? And what is class_double then? > > My apologies if this is obvious, but as I said, I find this confusing.It's documented that inherits(1.0, class_double) should execute inherits(1.0, "double") because nameOfClass(class_double) is "double". So things are consistent because you found inherits(1.0, "double") == inherits(1.0, class_double) And nameOfClass(class_numeric) is NULL, because the S7 authors haven't given a way for an S7 union to have an S3 class name. So I think you are right to be confused, but the only solution I can think of (allowing S7 unions to have S3 names) might be seen as just too much trouble. Are there any other cases where an S7 union corresponds to an S3 class? Duncan Murdoch