No solution yet, but adding some more context from the documentation for the Period class:
Period class objects have six slots.
- Data, a numeric object. The apparent amount of seconds to add to the period.
- minute, a numeric object. The apparent amount of minutes to add to the period.
- hour, a numeric object. The apparent amount of hours to add to the period.
- day, a numeric object. The apparent amount of days to add to the period.
- month, a numeric object. The apparent amount of months to add to the period.
- year, a numeric object. The apparent amount of years to add to the period.
I guess the next question would be if it works with Interval class objects (since @dromano has tested it out with Durations)
The answer seems to be a resounding no there:
suppressPackageStartupMessages(library(tidyverse))
library(lubridate)
date1 <- ymd_hms("2009-03-08 01:59:59")
date2 <- ymd_hms("2000-02-29 12:00:00")
intervals <- c(
interval(date2, date1),
interval((date2 - 1), (date1 - 1)),
interval((date2 - 2), (date1 - 2)),
interval((date2 - 3), (date1 - 3)),
interval((date2 - 4), (date1 - 4))
)
int_tib <- tibble::tibble(a = 1:5, b = intervals)
int_tib
#> # A tibble: 5 x 2
#> a b
#> <int> <Interval>
#> 1 1 2000-02-29 12:00:00 UTC--2009-03-08 01:59:59 UTC
#> 2 2 2000-02-29 11:59:59 UTC--2009-03-08 01:59:58 UTC
#> 3 3 2000-02-29 11:59:58 UTC--2009-03-08 01:59:57 UTC
#> 4 4 2000-02-29 11:59:57 UTC--2009-03-08 01:59:56 UTC
#> 5 5 2000-02-29 11:59:56 UTC--2009-03-08 01:59:55 UTC
nested <- int_tib %>% nest(b2 = b)
nested
#> # A tibble: 5 x 2
#> a b2
#> <int> <list>
#> 1 1 <tibble [1 × 1]>
#> 2 2 <tibble [1 × 1]>
#> 3 3 <tibble [1 × 1]>
#> 4 4 <tibble [1 × 1]>
#> 5 5 <tibble [1 × 1]>
unnested <- nested %>% unnest(cols = b2)
#> Error: No common type for `..1$b2$b` <Interval> and `..2$b2$b` <Interval>.
#> Backtrace:
#> █
#> 1. ├─nested %>% unnest(cols = b2)
#> 2. │ ├─base::withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
#> 3. │ └─base::eval(quote(`_fseq`(`_lhs`)), env, env)
#> 4. │ └─base::eval(quote(`_fseq`(`_lhs`)), env, env)
#> 5. │ └─`_fseq`(`_lhs`)
#> 6. │ └─magrittr::freduce(value, `_function_list`)
#> 7. │ ├─base::withVisible(function_list[[k]](value))
#> 8. │ └─function_list[[k]](value)
#> 9. │ ├─tidyr::unnest(., cols = b2)
#> 10. │ └─tidyr:::unnest.data.frame(., cols = b2)
#> 11. │ └─tidyr::unchop(data, !!cols, keep_empty = keep_empty, ptype = ptype)
#> 12. │ └─vctrs::vec_rbind(!!!x, .ptype = ptype)
#> 13. ├─vctrs:::vec_ptype2_dispatch_s3(x = x, y = y, x_arg = x_arg, y_arg = y_arg)
#> 14. └─vctrs:::vec_ptype2.default(x = x, y = y, x_arg = x_arg, y_arg = y_arg)
#> 15. └─vctrs::stop_incompatible_type(x, y, x_arg = x_arg, y_arg = y_arg)
#> 16. └─vctrs:::stop_incompatible(...)
#> 17. └─vctrs:::stop_vctrs(...)
Created on 2020-03-18 by the reprex package (v0.3.0.9001)
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 3.6.2 (2019-12-12)
#> os macOS Mojave 10.14.6
#> system x86_64, darwin15.6.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz America/New_York
#> date 2020-03-18
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)
#> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.0)
#> broom 0.5.5 2020-02-29 [1] CRAN (R 3.6.0)
#> cellranger 1.1.0 2016-07-27 [1] CRAN (R 3.6.0)
#> cli 2.0.2.9000 2020-03-02 [1] Github (r-lib/cli@a8b708e)
#> colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.0)
#> crayon 1.3.4 2020-02-02 [1] Github (r-lib/crayon@f4bc7b8)
#> DBI 1.1.0 2019-12-15 [1] CRAN (R 3.6.1)
#> dbplyr 1.4.2 2019-06-17 [1] CRAN (R 3.6.0)
#> digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.0)
#> dplyr * 0.8.99.9001 2020-03-18 [1] Github (tidyverse/dplyr@fbefa13)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0)
#> fansi 0.4.1 2020-01-09 [1] Github (brodieG/fansi@7ccb892)
#> forcats * 0.5.0.9000 2020-03-04 [1] Github (tidyverse/forcats@1c93496)
#> fs 1.3.2.9000 2020-03-18 [1] Github (r-lib/fs@1744061)
#> generics 0.0.2 2018-11-29 [1] CRAN (R 3.6.0)
#> ggplot2 * 3.3.0.9000 2020-03-16 [1] Github (tidyverse/ggplot2@3ddfc3f)
#> glue 1.3.2 2020-03-16 [1] Github (tidyverse/glue@0cbbb17)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.0)
#> haven 2.2.0 2019-11-08 [1] CRAN (R 3.6.0)
#> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0)
#> hms 0.5.3 2020-01-08 [1] CRAN (R 3.6.1)
#> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.0)
#> httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.1)
#> jsonlite 1.6.1 2020-02-02 [1] CRAN (R 3.6.1)
#> knitr 1.28 2020-02-06 [1] CRAN (R 3.6.0)
#> lattice 0.20-40 2020-02-19 [1] CRAN (R 3.6.0)
#> lifecycle 0.2.0.9000 2020-03-16 [1] Github (r-lib/lifecycle@355dcba)
#> lubridate * 1.7.4.9000 2020-03-18 [1] Github (tidyverse/lubridate@b922845)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0)
#> modelr 0.1.6 2020-02-22 [1] CRAN (R 3.6.0)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.0)
#> nlme 3.1-145 2020-03-04 [1] CRAN (R 3.6.0)
#> pillar 1.4.3.9000 2020-01-06 [1] Github (r-lib/pillar@8f5918c)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1)
#> purrr * 0.3.3.9000 2020-03-10 [1] Github (tidyverse/purrr@aa7bc7f)
#> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.0)
#> Rcpp 1.0.4.2 2020-03-18 [1] Github (RcppCore/Rcpp@20e462f)
#> readr * 1.3.1 2018-12-21 [1] CRAN (R 3.6.0)
#> readxl 1.3.1 2019-03-13 [1] CRAN (R 3.6.0)
#> reprex 0.3.0.9001 2020-02-02 [1] Github (tidyverse/reprex@a019cc4)
#> rlang 0.4.5.9000 2020-03-18 [1] Github (r-lib/rlang@a90b04b)
#> rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.1)
#> rstudioapi 0.11 2020-02-07 [1] CRAN (R 3.6.0)
#> rvest 0.3.5 2019-11-08 [1] CRAN (R 3.6.0)
#> scales 1.1.0.9000 2020-03-16 [1] Github (r-lib/scales@1e2c918)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0)
#> stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.0)
#> stringr * 1.4.0 2019-02-10 [1] CRAN (R 3.6.0)
#> styler 1.3.2 2020-02-23 [1] CRAN (R 3.6.1)
#> tibble * 2.99.99.9014 2020-03-18 [1] Github (tidyverse/tibble@7673f9e)
#> tidyr * 1.0.2.9000 2020-03-10 [1] Github (tidyverse/tidyr@bcfc5f0)
#> tidyselect 1.0.0.9000 2020-02-02 [1] Github (r-lib/tidyselect@bb145af)
#> tidyverse * 1.3.0 2019-11-21 [1] CRAN (R 3.6.1)
#> utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.0)
#> vctrs 0.2.99.9010 2020-03-18 [1] Github (r-lib/vctrs@27b4b96)
#> withr 2.1.2.9000 2020-02-02 [1] Github (r-lib/withr@16d47fd)
#> xfun 0.12 2020-01-13 [1] CRAN (R 3.6.0)
#> xml2 1.2.5 2020-03-11 [1] CRAN (R 3.6.2)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.1)
#> ymlthis 0.1.2.9000 2020-03-16 [1] Github (r-lib/ymlthis@d4f983a)
#>
#> [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library