Skip to content

Commit aac781b

Browse files
committed
wip support different types of time_step/time_type
1 parent 955e816 commit aac781b

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

R/slide.R

+25-9
Original file line numberDiff line numberDiff line change
@@ -567,16 +567,32 @@ epi_slide_mean = function(x, col_name, ..., before, after, ref_time_values,
567567
# after <- time_step(after)
568568
# }
569569

570-
# time_step can be any of `c("days", "weeks", "months", "quarters", "years")`
571-
all_dates <- seq(min(x$time_value), max(x$time_value), by = time_step)
570+
all_dates <- as.Date(c())
571+
pad_early_dates <- as.Date(c())
572+
pad_late_dates <- as.Date(c())
572573

573-
pad_early_dates <- c()
574-
pad_late_dates <- c()
575-
if (before != 0) {
576-
pad_early_dates <- all_dates[1L] - before:1
577-
}
578-
if (after != 0) {
579-
pad_late_dates <- all_dates[length(all_dates)] + 1:after
574+
# Find `by` corresponding to epi_df `time_type` or `time_step`.
575+
by <- ...
576+
577+
if (!is.null(by)) {
578+
# time_step can be any of `c("days", "weeks", "months", "quarters", "years")`
579+
# tidyr::full_seq(c(min(x$time_value), max(x$time_value)), period = 1) ?
580+
all_dates <- seq(min(x$time_value), max(x$time_value), by = by)
581+
582+
if (before != 0) {
583+
pad_early_dates <- Start(all_dates) - before:1
584+
}
585+
if (after != 0) {
586+
pad_late_dates <- End(all_dates) + 1:after
587+
}
588+
} else {
589+
Warn(
590+
c(
591+
"`frollmean` requires a full window to compute a result. Add NA values
592+
to beginning and end of the group so that we get results for the
593+
first `before` and last `after` elements."
594+
)
595+
)
580596
}
581597

582598
# `frollmean` is 1-indexed, so create a new window width based on our

0 commit comments

Comments
 (0)