-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Reinstate support for filtering and arranging lubridate Periods and Intervals #3695
Comments
Are you sure these features worked as expected? How is comparison defined between intervals? We should definitely introduce proper support for these and other data types, #2432 is the canonical issue. |
@krlmlr Comparison for intervals was on the length of the interval (in seconds) – I think this is reasonable. You can use |
There are a few things we need to figure out before we can make these things work again. Some code will need to be factored out of dplyr or reimplemented so that 📦 like lubridate can implement a method that does the right thing without necessarily depend on dplyr. This is probably for the 0.9.0 horizon at least |
|
They both work for intervals, but the comparison is only done through the library(dplyr, warn.conflicts = FALSE)
library(lubridate, warn.conflicts = FALSE)
x <- data_frame(
start = as.Date("2000-01-01") + 0:3,
finish = as.Date("2001-01-01") + 3:0,
interval = start %--% finish
)
x$interval
#> [1] 2000-01-01 UTC--2001-01-04 UTC 2000-01-02 UTC--2001-01-03 UTC
#> [3] 2000-01-03 UTC--2001-01-02 UTC 2000-01-04 UTC--2001-01-01 UTC
str(x$interval)
#> Formal class 'Interval' [package "lubridate"] with 3 slots
#> ..@ .Data: num [1:4] 31881600 31708800 31536000 31363200
#> ..@ start: POSIXct[1:4], format: "2000-01-01" ...
#> ..@ tzone: chr "UTC"
x %>%
arrange(interval)
#> # A tibble: 4 x 3
#> start finish interval
#> <date> <date> <S4: Interval>
#> 1 2000-01-04 2001-01-01 2000-01-04 UTC--2001-01-01 UTC
#> 2 2000-01-03 2001-01-02 2000-01-03 UTC--2001-01-02 UTC
#> 3 2000-01-02 2001-01-03 2000-01-02 UTC--2001-01-03 UTC
#> 4 2000-01-01 2001-01-04 2000-01-01 UTC--2001-01-04 UTC
x %>%
arrange(interval@.Data)
#> # A tibble: 4 x 3
#> start finish interval
#> <date> <date> <S4: Interval>
#> 1 2000-01-04 2001-01-01 2000-01-04 UTC--2001-01-01 UTC
#> 2 2000-01-03 2001-01-02 2000-01-03 UTC--2001-01-02 UTC
#> 3 2000-01-02 2001-01-03 2000-01-02 UTC--2001-01-03 UTC
#> 4 2000-01-01 2001-01-04 2000-01-01 UTC--2001-01-04 UTC
x %>%
filter(interval > 0)
#> # A tibble: 4 x 3
#> start finish interval
#> <date> <date> <S4: Interval>
#> 1 2000-01-01 2001-01-04 2000-01-01 UTC--2001-01-04 UTC
#> 2 2000-01-02 2001-01-03 2000-01-02 UTC--2001-01-03 UTC
#> 3 2000-01-03 2001-01-02 2000-01-03 UTC--2001-01-02 UTC
#> 4 2000-01-04 2001-01-01 2000-01-04 UTC--2001-01-01 UTC
x %>%
filter(interval@.Data > 0)
#> # A tibble: 4 x 3
#> start finish interval
#> <date> <date> <S4: Interval>
#> 1 2000-01-01 2001-01-04 2000-01-01 UTC--2001-01-04 UTC
#> 2 2000-01-02 2001-01-03 2000-01-02 UTC--2001-01-03 UTC
#> 3 2000-01-03 2001-01-02 2000-01-03 UTC--2001-01-02 UTC
#> 4 2000-01-04 2001-01-01 2000-01-04 UTC--2001-01-01 UTC Created on 2018-12-14 by the reprex package (v0.2.1.9000) |
Duplicate of #2432 |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
Support for
filter()
ing andarrange()
ing columns of classPeriod
andInterval
was recently dropped fromdplyr
. The ability to work with these types is useful, so I'd like the feature reinstating.(By 'useful', I mean in particular that there are DataCamp courses depending upon this feature. For example, Working with Dates and Times in R.)
To reproduce:
The text was updated successfully, but these errors were encountered: