Thanks, Duncan (and Rui).

This is basically what I "concluded" in my post; but my grasp of such
things is shaky, at best, so I thought I may have missed something more or
less obvious.

Perhaps also worth noting is:

> is.numeric
function (x)  .Primitive("is.numeric")

so that my whole notion of a numeric constant in the language having a
*formal* class is probably misguided/dumb to begin with. It only "works" in
S3 due to S3's informal nature, as ?new_S3_class alludes. But the clash of
names that you note certainly threw me.

Best,
Bert

On Mon, Jan 5, 2026 at 11:16 AM Duncan Murdoch <[email protected]>
wrote:

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

        [[alternative HTML version deleted]]

______________________________________________
[email protected] 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.

Reply via email to