Skip to content
Prev 63422 / 63424 Next

Should as() find an ANY method even for an 'unregistered' S3 class?

> OK, here is a self-contained version

    > setClass("integer64")
    > setAs("ANY", "integer64", function(from) {
    >    structure(from, class = "integer64")
    > })
    > x <- 1e10
    > class(x) <- c("foo", "integer64")
    > as(x, "integer64")
    > # Error in as(x, "integer64") :
    > #   internal problem in as(): ?foo? is(object, "integer64") is TRUE, but
    > the metadata asserts that the 'is' relation is FALSE

    > Mike C

Thank you, Mike!

That is indeed  "not nice": I'm almost sure I've never seen this
"in the wild", and the    "internal problem in "
part of the error message does suggest that it also seemed
improbable to the programmeR at the time that this would happen
"in the wild".

I could argue that this is a really atypical unusual mixup of
using S4 technology with S3  about which I'd be correct,
but I think this does warrant a bugzilla bug report.
It's not clear to me yet *what* should be fixed / changed
(possibly only the error message ..),
but the current way is clearly not satisfactory.

Martin



    > On Thu, Mar 19, 2026 at 2:11?AM Martin Maechler <maechler at stat.math.ethz.ch>
> wrote:
>> >>>>> Michael Chirico
    >> >>>>>     on Wed, 18 Mar 2026 10:40:11 -0700 writes:
    >> 
    >> > We have
    >> >      setAs("ANY", "integer64", function(from) as.integer64(from))
    >> 
    >> Sorry, but  who is "we"?
    >> R does not know about "integer64" nor an as.integer64()
    >> 
    >> I'd expect knowledgable posters to R-devel  to use reproducible
    >> examples, please !?
    >> 
    >> Martin
    >> 
    >> > I expected that would work to default as(x, "integer64")
    >> > to use the S3 coercion, but not so for a different S3
    >> > class:
    >> 
    >> > x = 1e10 class(x) = c("foo", "integer64") as(x,
    >> > "integer64") # Error in as(x, "integer64") : # internal
    >> > problem in as(): ?foo? is(object, "integer64") is TRUE,
    >> > but the metadata asserts that the 'is' relation is FALSE
    >> 
    >> ....
    >> 

    > [[alternative HTML version deleted]]