Skip to content

Commit

Permalink
wip support different types of time_step/time_type
Browse files Browse the repository at this point in the history
  • Loading branch information
nmdefries committed Jan 25, 2024
1 parent a51e7ee commit 2d42c4f
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions R/slide.R
Original file line number Diff line number Diff line change
Expand Up @@ -567,16 +567,32 @@ epi_slide_mean = function(x, col_name, ..., before, after, ref_time_values,
# after <- time_step(after)
# }

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

pad_early_dates <- c()
pad_late_dates <- c()
if (before != 0) {
pad_early_dates <- all_dates[1L] - before:1
}
if (after != 0) {
pad_late_dates <- all_dates[length(all_dates)] + 1:after
# Find `by` corresponding to epi_df `time_type` or `time_step`.
by <- ...

if (!is.null(by)) {
# time_step can be any of `c("days", "weeks", "months", "quarters", "years")`
# tidyr::full_seq(c(min(x$time_value), max(x$time_value)), period = 1) ?
all_dates <- seq(min(x$time_value), max(x$time_value), by = by)

if (before != 0) {
pad_early_dates <- Start(all_dates) - before:1
}
if (after != 0) {
pad_late_dates <- End(all_dates) + 1:after
}
} else {
Warn(
c(
"`frollmean` requires a full window to compute a result. Add NA values
to beginning and end of the group so that we get results for the
first `before` and last `after` elements."
)
)
}

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

0 comments on commit 2d42c4f

Please sign in to comment.