>>>>> Michael Chirico 
>>>>>     on Thu, 5 Mar 2026 14:26:16 -0800 writes:

    > I found myself needing to add methods::setOldClass("difftime") in
    > order to also set a coercion method for my class to difftime:

    > methods::setAs("myClass", "difftime", ...)

    > And thus avoid the on-load message:

    > in method for ‘coerce’ with signature ‘"myClass","difftime"’: no
    > definition for class “difftime”

    > I see 10 or so other packages also doing the same [1].

    > I am wondering, though, since {base} owns this class, if it shouldn't
    > be registered already? I see inclusions for, e.g., closely-related S3
    > classes Date and POSIXt [2].

In my vague recollection  "difftime" came a bit later than "Date"
and "POSIXlt".  This may be the reason for its non-presence.

    > OTOH, I see .OldClassesList hasn't really been edited in 15+ years, so
    > maybe this approach has lost favor and is better not amended anymore
    > [3].

well, favors related to S4 have always been somewhat segregated ..

    > (or maybe this is really an r-package-devel question about whether
    > supporting as(<my class>, "difftime") is actually beneficial...)

The use of  as(., <...>)  is an R-help question really  not
restricted to package development at all.

I agree that "difftime" does naturally belong alongside "POSIXt"
and I am happy to add it to the list;
(I did check to see if an unneeded   setOldClass(<already_set>)
 gives a warning, and it doesn't)

Martin


    > Mike C

    > [1] 
https://github.com/search?q=org%3Acran%20%2FsetOldClass.*difftime%2F&type=code
    > [2] 
https://github.com/r-devel/r-svn/blob/b7850c8cae0956592019c5f8f59e885d3d39ae6f/src/library/methods/R/BasicClasses.R#L550-L552
    > [3] 
https://github.com/r-devel/r-svn/blame/b7850c8cae0956592019c5f8f59e885d3d39ae6f/src/library/methods/R/BasicClasses.R#L541-L569

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to