Comparing
methods(class = "IDate")
# [1] as.Date as.list as.POSIXct c coerce cut
# [7] initialize mean rep round seq show
# [13] slotsFromS3 split unique
With
methods(class = "Date")
# [1] as.character as.data.frame as.data.table as.IDate as.list
# [6] as.POSIXct as.POSIXlt Axis c coerce
# [11] cut - [<- [ [[
# [16] + diff format hist initialize
# [21] is.numeric julian Math mean months
# [26] Ops pretty print quarters rep
# [31] round seq show slotsFromS3 split
# [36] str summary Summary trunc weekdays
# [41] weighted.mean xtfrm
We see there's a lot of minor stuff to take care of to get IDate on par with Date for built in methods (and to help make sure we're not accidentally converting to Date along the way).
Specifically, we can add the following:
but they should be dispatched to next method, so Date method, we may only need to adjust class on returning object.
Anyway I would prefer to wait for #1451
The hope is that there's some efficiency gains, especially if the Date method forces numeric before we force integer again.
I'm gonna handle this myself, so no need to divert resources from more important things.
Was about to post a new issue (titled "replace() returns invalid IDates") before I saw this. There are good reasons for at least some of these besides efficiency, I guess.
Here's an example for [<-.IDate:
library(data.table)
z = replace(as.IDate(Sys.Date() + 1:2), 1L, as.IDate(Sys.Date()-1L))
dput(z)
# structure(c(17189, 17192), class = c("IDate", "Date"))
As you can see, the storage format of the vector is not integer and yet the class still claims to be IDate.
This was a problem for me because I stored this vector as a column alongside a legit IDate and then used melt, which correctly gave me the warning
'measure.vars' [z, d] are not all of the same type. [...]
and gave me back an unclassed double.
Maybe the problem is that replace uses [<-, and that gets dispatched to [<-.Date which contains a pernicious as.Date(value) line, so maybe a dedicated [<-.IDate.
Btw, thanks for taking these on, Michael.
trunc is probably worth to have. There is dedicated issue for it https://github.com/Rdatatable/data.table/issues/4335 and related SO https://stackoverflow.com/questions/65614603/performance-properties-of-time-series-operations-in-r-at-scale-mainly-xts-and-d
Most helpful comment
Was about to post a new issue (titled "replace() returns invalid IDates") before I saw this. There are good reasons for at least some of these besides efficiency, I guess.
Here's an example for
[<-.IDate:As you can see, the storage format of the vector is not
integerand yet the class still claims to beIDate.This was a problem for me because I stored this vector as a column alongside a legit IDate and then used
melt, which correctly gave me the warningand gave me back an unclassed double.
Maybe the problem is that
replaceuses[<-, and that gets dispatched to[<-.Datewhich contains a perniciousas.Date(value)line, so maybe a dedicated[<-.IDate.Btw, thanks for taking these on, Michael.