Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completing the roster of .IDate methods with companion .Date methods #1695

Open
3 of 29 tasks
MichaelChirico opened this issue May 9, 2016 · 4 comments
Open
3 of 29 tasks

Comments

@MichaelChirico
Copy link
Member

MichaelChirico commented May 9, 2016

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:

  • as.character
  • as.data.frame
  • as.data.table
  • as.POSIXlt
  • Axis
  • -
  • [<-
  • [
  • [[
  • diff
  • format
  • hist
  • is.numeric
  • julian
  • Math
  • mean
  • months
  • Ops
  • pretty
  • print
  • quarters
  • split
  • str
  • summary
  • Summary
  • trunc
  • weekdays
  • weighted.mean
  • xtfrm
@jangorecki

This comment has been minimized.

@MichaelChirico

This comment has been minimized.

@franknarf1
Copy link
Contributor

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.

@jangorecki
Copy link
Member

trunc is probably worth to have. There is dedicated issue for it #4335 and related SO https://stackoverflow.com/questions/65614603/performance-properties-of-time-series-operations-in-r-at-scale-mainly-xts-and-d

@jangorecki jangorecki added this to the 1.13.7 milestone Jan 8, 2021
@mattdowle mattdowle removed this from the 1.14.1 milestone Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants