You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I ran into a small issue with the new POSIXxt objects stringx introduces where the substraction method doesn't work.
For instance we know this works
aa = base::Sys.time()
bb = base::Sys.time()
bb - aa
Time difference of 0.002556086 secs
But currently the following gives an error
aa = stringx::Sys.time()
bb = stringx::Sys.time()
bb - aa
bb - aa
Error in as.POSIXct.default(x, tz = tz, ...) :
do not know how to convert 'x' to class “POSIXct”
I found that this occurs because the class of stringx::Sys.time() is
"POSIXxt" "POSIXct" "POSIXt" so the - doesn't know how to handle it when it finds POSIXxt instead of the internal POSIX classes.
For my case I managed this with a very simple work around by introducing the `-.POSIXxt' S3 method like the following
`-.POSIXxt` <- function(...) difftime(...)
#Now the subtraction works
bb-aa
Time difference of 0.002810955 secs
This works great but I think the internal '-.POSIXxt' is a little more comprehensive so the following also works, but i find this a litte hacky because here I simply revert the class attribute) to trick the subtraction method to find the "POSIXxt" when it looks for that attribute.
These are my naive workarounds, but I am sure there is a more comprehensive and elegant way to add this method in the library.
I think that having having these internal POSIXt methods for the POSIXxt class in the library is important for improved compatibility with the base package.
Thanks
The text was updated successfully, but these errors were encountered:
Hi, I ran into a small issue with the new POSIXxt objects stringx introduces where the substraction method doesn't work.
For instance we know this works
But currently the following gives an error
I found that this occurs because the class of stringx::Sys.time() is
"POSIXxt" "POSIXct" "POSIXt" so the
-
doesn't know how to handle it when it finds POSIXxt instead of the internal POSIX classes.For my case I managed this with a very simple work around by introducing the `-.POSIXxt' S3 method like the following
This works great but I think the internal '-.POSIXxt' is a little more comprehensive so the following also works, but i find this a litte hacky because here I simply revert the class attribute) to trick the subtraction method to find the "POSIXxt" when it looks for that attribute.
These are my naive workarounds, but I am sure there is a more comprehensive and elegant way to add this method in the library.
I think that having having these internal POSIXt methods for the POSIXxt class in the library is important for improved compatibility with the base package.
Thanks
The text was updated successfully, but these errors were encountered: