Closed DanChaltiel closed 1 week ago
Date
comes from base R, not from lubridate, so I don't think it would be appropriate for us to write an S3 method in this case.
You can use vctrs::vec_set_difference()
if you need a generic version that works with pretty much all S3 types.
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
a = seq(as_date(1), as_date(10), by=1)
b = seq(as_date(5), as_date(10), by=1)
vctrs::vec_set_difference(a, b)
#> [1] "1970-01-02" "1970-01-03" "1970-01-04" "1970-01-05"
Created on 2024-08-05 with reprex v2.0.2
Hi,
Using set operations like
setdiff
on dates removes the date class.Here is a reprex with a very naive workaround:
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 forDate
. I'm not using other lubridate classes much but maybe they have the same problem.