Closed DavisVaughan closed 1 year ago
Something like this
devtools::load_all()
#> ℹ Loading clock
calendar_expand <- function(x) {
if (vec_size(x) == 0L) {
x <- unname(x)
return(x)
}
precision <- calendar_precision_attribute(x)
by <- duration_helper(1L, precision = precision)
# wrong right now if there are NAs due to CRAN vctrs xtfrm()
x <- range(x)
seq(from = x[[1]], to = x[[2]], by = by)
}
calendar_expand(year_month_day(2021:2022, 2))
#> <year_month_day<month>[13]>
#> [1] "2021-02" "2021-03" "2021-04" "2021-05" "2021-06" "2021-07" "2021-08"
#> [8] "2021-09" "2021-10" "2021-11" "2021-12" "2022-01" "2022-02"
calendar_expand(year_month_day(integer()))
#> <year_month_day<year>[0]>
Uncertain if expand is the right name for this - tidyr::expand()
expands on all combinations. It doesn't fill in implicitly missing values.
Similar idea to
tidyr::full_seq()
calendar_expand()
works with year/quarter/month precision inputstime_point_expand()
works with week...nanosecond precision inputsseq()
methodsdate_expand()
uses day precision for Date and second precision for POSIXt, powered by the aboveProbably needs good definitions of
min()
andmax()
for all calendar / time-point types. In particular,min()
andmax()
of empty calendar / time-point objects, which should return the max and min allowed values respectively, which are currently a little hard to define right now and are precision specific