Skip to content

Commit

Permalink
fix: .ref_time_values -> .versions in epix_slide and some doc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dshemetov committed Sep 19, 2024
1 parent 48735c5 commit 227e133
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ print.epi_archive <- function(x, ..., class = TRUE, methods = TRUE) {
#' epix_slide(
#' .f = ~ mean(.x$case_rate_7d_av),
#' .before = 2,
#' .ref_time_values = as.Date("2020-06-11") + 0:2,
#' .versions = as.Date("2020-06-11") + 0:2,
#' .new_col_name = "case_rate_3d_av"
#' ) %>%
#' ungroup()
Expand Down
13 changes: 10 additions & 3 deletions R/grouped_epi_archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,20 @@ epix_slide.grouped_epi_archive <- function(
# early development versions and much more likely to be clutter than
# informative in the signature.
provided_args <- rlang::call_args_names(rlang::call_match())
if (any(provided_args %in% c("x", "f", "before", "ref_time_values", "new_col_name", "all_versions"))) {
if (any(provided_args %in% c(

Check warning on line 227 in R/grouped_epi_archive.R

View workflow job for this annotation

GitHub Actions / lint

file=R/grouped_epi_archive.R,line=227,col=30,[object_usage_linter] missing arguments not allowed in calls to 'c'
"x", "f", "before", "new_col_name", "all_versions",
))) {
cli::cli_abort(
"epix_slide: you are using one of the following old argument names: `x`, `f`, `before`, `ref_time_values`,
`new_col_name`, `all_versions`. Please use the new names: `.x`, `.f`, `.before`, `.ref_time_values`,
"epix_slide: you are using one of the following old argument names: `x`, `f`, `before`,
`new_col_name`, `all_versions`. Please use the new names: `.x`, `.f`, `.before`,
`.new_col_name`, `.all_versions`."
)
}
if (any(provided_args %in% c("ref_time_values", ".ref_time_values"))) {
cli::cli_abort(
"epix_slide: the argument `ref_time_values` is deprecated. Please use `.versions` instead."
)
}
if ("group_by" %in% provided_args) {
cli_abort("
The `group_by` argument to `slide` has been removed; please use
Expand Down
12 changes: 6 additions & 6 deletions R/methods-epi_archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ epix_detailed_restricted_mutate <- function(.data, ...) {
#' in the archive is "day", and the `.ref_time_value` is January 8, then the
#' smallest time_value in the snapshot will be January 1. If missing, then the
#' default is no limit on the time values, so the full snapshot is given.
#' @param .ref_time_values Reference time values / versions for sliding
#' @param .versions Reference time values / versions for sliding
#' computations; each element of this vector serves both as the anchor point
#' for the `time_value` window for the computation and the `max_version`
#' `epix_as_of` which we fetch data in this window. If missing, then this will
Expand Down Expand Up @@ -712,7 +712,7 @@ epix_detailed_restricted_mutate <- function(.data, ...) {
#' computations are allowed more flexibility in their outputs than in
#' `epi_slide`, we can't guess a good representation for missing computations
#' for excluded group-`.ref_time_value` pairs.
#' 76. The `.ref_time_values` default for `epix_slide` is based on making an
#' 76. The `.versions` default for `epix_slide` is based on making an
#' evenly-spaced sequence out of the `version`s in the `DT` plus the
#' `versions_end`, rather than the `time_value`s.
#'
Expand All @@ -731,7 +731,7 @@ epix_detailed_restricted_mutate <- function(.data, ...) {
#' library(dplyr)
#'
#' # Reference time points for which we want to compute slide values:
#' ref_time_values <- seq(as.Date("2020-06-01"),
#' versions <- seq(as.Date("2020-06-01"),
#' as.Date("2020-06-15"),
#' by = "1 day"
#' )
Expand All @@ -743,7 +743,7 @@ epix_detailed_restricted_mutate <- function(.data, ...) {
#' epix_slide(
#' .f = ~ mean(.x$case_rate_7d_av),
#' .before = 2,
#' .ref_time_values = ref_time_values,
#' .versions = versions,
#' .new_col_name = "case_rate_7d_av_recent_av"
#' ) %>%
#' ungroup()
Expand Down Expand Up @@ -777,7 +777,7 @@ epix_detailed_restricted_mutate <- function(.data, ...) {
#' )
#' },
#' .before = 5, .all_versions = FALSE,
#' .ref_time_values = ref_time_values
#' .versions = versions
#' ) %>%
#' ungroup() %>%
#' arrange(geo_value, time_value)
Expand Down Expand Up @@ -812,7 +812,7 @@ epix_detailed_restricted_mutate <- function(.data, ...) {
#' )
#' },
#' .before = 5, .all_versions = TRUE,
#' .ref_time_values = ref_time_values
#' .versions = versions
#' ) %>%
#' ungroup() %>%
#' # Focus on one geo_value so we can better see the columns above:
Expand Down
4 changes: 2 additions & 2 deletions vignettes/advanced.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ edf %>%
mutate(version = time_value) %>%
as_epi_archive() %>%
group_by(geo_value) %>%
epix_slide(x_2dav = mean(x), .before = 1, .ref_time_values = as.Date("2020-06-02")) %>%
epix_slide(x_2dav = mean(x), .before = 1, .versions = as.Date("2020-06-02")) %>%
ungroup()
edf %>%
Expand Down Expand Up @@ -429,7 +429,7 @@ k_week_ahead <- function(x, ahead = 7, as_of = TRUE) {
fc = prob_arx(.data$percent_cli, .data$case_rate_7d_av, .data$geo_value, .data$time_value,
args = prob_arx_args(ahead = ahead)
),
.before = 219, .ref_time_values = fc_time_values
.before = 219, .versions = fc_time_values
) %>%
mutate(
target_date = .data$time_value + ahead, as_of = TRUE,
Expand Down
6 changes: 3 additions & 3 deletions vignettes/archive.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ z <- x %>%
group_by(geo_value) %>%
epix_slide(
fc = prob_arx(x = percent_cli, y = case_rate_7d_av), .before = 119,
.ref_time_values = fc_time_values
.versions = fc_time_values
) %>%
ungroup()
Expand Down Expand Up @@ -383,7 +383,7 @@ k_week_ahead <- function(x, ahead = 7, as_of = TRUE) {
group_by(.data$geo_value) %>%
epix_slide(
fc = prob_arx(.data$percent_cli, .data$case_rate_7d_av, ahead = ahead), .before = 119,
.ref_time_values = fc_time_values
.versions = fc_time_values
) %>%
mutate(target_date = .data$time_value + ahead, as_of = TRUE) %>%
ungroup()
Expand All @@ -392,7 +392,7 @@ k_week_ahead <- function(x, ahead = 7, as_of = TRUE) {
group_by(.data$geo_value) %>%
epi_slide(
fc = prob_arx(.data$percent_cli, .data$case_rate_7d_av, ahead = ahead), .window_size = 120,
.ref_time_values = fc_time_values
.versions = fc_time_values
) %>%
mutate(target_date = .data$time_value + ahead, as_of = FALSE) %>%
ungroup()
Expand Down

0 comments on commit 227e133

Please sign in to comment.