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

Implement Set Operations methods for Dates #1155

Open
DanChaltiel opened this issue Feb 6, 2024 · 0 comments
Open

Implement Set Operations methods for Dates #1155

DanChaltiel opened this issue Feb 6, 2024 · 0 comments

Comments

@DanChaltiel
Copy link

DanChaltiel commented Feb 6, 2024

Hi,

Using set operations like setdiff on dates removes the date class.

Here is a reprex with a very naive workaround:

library(lubridate)  
a = seq(as_date(1), as_date(10), by=1) 
b = seq(as_date(5), as_date(10), by=1) 

setdiff(a, b)  
#> [1] 1 2 3 4

setdiff.Date = function(x, y) base::setdiff(x, y) |> as_date()
setdiff(a, b)
#> [1] "1970-01-02" "1970-01-03" "1970-01-04" "1970-01-05"

Created on 2024-02-06 with reprex v2.0.2

Of course, the same problem and solution happen for other set operations like intersect and others.

I guess that since they are implemented for the Interval class, it would make sense to implement them for Date. I'm not using other lubridate classes much but maybe they have the same problem.

@DanChaltiel DanChaltiel changed the title Implement a setdiff.Date() method Implement Set Operations methods for Dates Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant