Unexpected lubridate interval behavior when filtering dataframe via dplyr

Viewed 186

I am creating a lubridate interval vector using a dataset similar to that which is available in the following chunk:

dat <- readr::read_rds(url("https://github.com/mienkoja/stack_stash/blob/master/dat.rds?raw=true"))

dat_mod <- dplyr::mutate(dat, interval = lubridate::interval(lubridate::ymd(start_combo)
                                                             ,lubridate::ymd(stop_combo)))

If I try to filter the object via dplyr, however, I get an unexpected interval returned:

dplyr::filter(dat_mod, id == 7000)

## A tibble: 1 x 4
#     id start_combo stop_combo                       interval
#  <int>       <dbl>      <dbl>                 <S4: Interval>
#1  7000    20170802   20170816 2016-10-11 UTC--2016-10-25 UTC

Indeed, every interval (viewed via dplyr::filter) appears to be the same length as the expected interval, but all anchored (incorrectly) to 2016-10-11 UTC.

I suspect this is a dplyr::filter bug as I can search by bracket notation and get the expected result.

dat_mod[dat_mod$id == 7000, ]

## A tibble: 1 x 4
#     id start_combo stop_combo                       interval
#  <int>       <dbl>      <dbl>                 <S4: Interval>
#1  7000    20170802   20170816 2017-08-02 UTC--2017-08-16 UTC

Before I report the bug, however, I figured I'd reach out here to see if I am missing something and this behavior is by design.


Question: Is it possible to use dplyr::filter and retrieve actual lubridate intervals (as retrieved via "bracket notation")?


Update: Since nobody has jumped on this, I am going to assume this is a bug for the time being. See the following issue posted on GitHub: https://github.com/tidyverse/dplyr/issues/3206

I'll update in both places once I get a fix (via GitHub) or a solution (via SO).

0 Answers
Related