Is "difftime" an appropriate addition to .OldClassesList?
Martin Maechler
on Fri, 6 Mar 2026 11:36:24 +0100 writes:
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)
With svn rev 89582, I have committed this now to "R-devel".
Thank you, Michael, for the suggestion!
Martin