tidyverse / lubridate

Make working with dates in R just that little bit easier
https://lubridate.tidyverse.org
GNU General Public License v3.0
731 stars 207 forks source link

R/intervals.r Error for checking interval within list of interval #1056

Closed jjcrumpler3 closed 2 years ago

jjcrumpler3 commented 2 years ago

Was attempting to check intervals within a dataframe for work to determine if they were within a list of intervals. However, the results would fail on my work computer, and my personal computer.

The reprex below was taken from the lubridate website... https://lubridate.tidyverse.org/reference/within-interval.html

The final example... int %within% lst

Does not appear to render without throwing the following error Error in int %within% lst : No %within% method with signature a = Interval, b = list

library(lubridate)

int <- interval(ymd("2001-01-01"), ymd("2002-01-01"))
int2 <- interval(ymd("2001-06-01"), ymd("2002-01-01"))

ymd("2001-05-03") %within% int # TRUE
#> [1] TRUE

int2 %within% int
#> [1] TRUE

ymd("1999-01-01") %within% int # FALSE
#> [1] FALSE

## recycling (carefully note the difference between using a vector of
## intervals and list of intervals for the second argument)

dates <- ymd(c("2014-12-20", "2014-12-30", "2015-01-01", "2015-01-03"))

blackout_vector <- c(interval(ymd("2014-12-30"), ymd("2014-12-31")),
                     interval(ymd("2014-12-30"), ymd("2015-01-03")))

dates %within% blackout_vector
#> [1] FALSE  TRUE FALSE  TRUE

## within ANY of the intervals of a list
dates <- ymd(c("2014-12-20", "2014-12-30", "2015-01-01", "2015-01-03"))

lst <- list(
  interval(ymd("2014-12-30"), ymd("2014-12-31")),
  interval(ymd("2014-12-30"), ymd("2015-01-03"))
)

dates %within% lst
#> [1] FALSE  TRUE  TRUE  TRUE

## interval within a list of intervals
int <- interval(
  ymd("2014-12-20", "2014-12-30"),
  ymd("2015-01-01", "2015-01-03")
)

int %within% lst

attached below is my sessioninfo in case that helps. Also, same error was thrown on my work computer as well which is a windows

─ Session info ────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.0 (2022-04-22)
 os       macOS Monterey 12.3
 system   x86_64, darwin17.0
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/New_York
 date     2022-07-15
 rstudio  2022.02.3+492 Prairie Trillium (desktop)
 pandoc   NA

─ Packages ──────────────────────────────────────────────────────────── package     * version date (UTC) lib source
 brio          1.1.3   2021-11-30 [1] CRAN (R 4.1.0)
 cachem        1.0.6   2021-08-19 [1] CRAN (R 4.1.0)
 callr         3.7.0   2021-04-20 [1] CRAN (R 4.1.0)
 cli           3.3.0   2022-04-25 [1] CRAN (R 4.1.2)
 crayon        1.5.1   2022-03-26 [1] CRAN (R 4.2.0)
 desc          1.4.1   2022-03-06 [1] CRAN (R 4.1.2)
 devtools      2.4.3   2021-11-30 [1] CRAN (R 4.1.0)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
 fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.2.0)
 fs            1.5.2   2021-12-08 [1] CRAN (R 4.2.0)
 generics      0.1.2   2022-01-31 [1] CRAN (R 4.2.0)
 glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.0)
 lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.1.0)
 lubridate   * 1.8.0   2021-10-07 [1] CRAN (R 4.2.0)
 magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.0)
 memoise       2.0.1   2021-11-26 [1] CRAN (R 4.1.0)
 pkgbuild      1.3.1   2021-12-20 [1] CRAN (R 4.1.0)
 pkgload       1.2.4   2021-11-30 [1] CRAN (R 4.1.0)
 prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.1.0)
 processx      3.6.0   2022-06-10 [1] CRAN (R 4.2.0)
 ps            1.7.0   2022-04-23 [1] CRAN (R 4.2.0)
 purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.0)
 remotes       2.4.2   2021-11-30 [1] CRAN (R 4.2.0)
 rlang         1.0.2   2022-03-04 [1] CRAN (R 4.2.0)
 rprojroot     2.0.3   2022-04-02 [1] CRAN (R 4.2.0)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.1.0)
 testthat      3.1.4   2022-04-26 [1] CRAN (R 4.1.2)
 usethis       2.1.6   2022-05-25 [1] CRAN (R 4.2.0)
 withr         2.5.0   2022-03-03 [1] CRAN (R 4.1.2)

 [1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library
jjcrumpler3 commented 2 years ago

Issue seemed to be user error, not package error.