Skip to content

Commit de948b5

Browse files
authored
wip: rework slide window args (#513)
* feat!: breaking rework to epi_slide interface
1 parent 871946f commit de948b5

19 files changed

+1030
-1010
lines changed

DESCRIPTION

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Imports:
3131
data.table,
3232
dplyr (>= 1.0.8),
3333
genlasso,
34-
glue,
3534
ggplot2,
3635
glue,
3736
lifecycle (>= 1.0.1),

R/autoplot.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ autoplot.epi_df <- function(
4747
.facet_by = c(".response", "other_keys", "all_keys", "geo_value", "all", "none"),
4848
.base_color = "#3A448F",
4949
.max_facets = Inf) {
50-
.color_by <- match.arg(.color_by)
51-
.facet_by <- match.arg(.facet_by)
50+
.color_by <- rlang::arg_match(.color_by)
51+
.facet_by <- rlang::arg_match(.facet_by)
5252

5353
assert(anyInfinite(.max_facets), checkInt(.max_facets), combine = "or")
5454
assert_character(.base_color, len = 1)

R/correlation.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ epi_cor <- function(x, var1, var2, dt1 = 0, dt2 = 0, shift_by = geo_value, # nol
9999
shift_by <- syms(names(eval_select(enquo(shift_by), x)))
100100

101101
# Which method?
102-
method <- match.arg(method)
102+
method <- rlang::arg_match(method)
103103

104104
# Perform time shifts, then compute appropriate correlations and return
105105
return(x %>%

R/growth_rate.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ growth_rate <- function(x = seq_along(y), y, x0 = x,
120120
# Check x, y, x0
121121
if (length(x) != length(y)) cli_abort("`x` and `y` must have the same length.")
122122
if (!all(x0 %in% x)) cli_abort("`x0` must be a subset of `x`.")
123-
method <- match.arg(method)
123+
method <- rlang::arg_match(method)
124124

125125
# Arrange in increasing order of x
126126
o <- order(x)

R/outliers.R

+3-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ detect_outlr <- function(x = seq_along(y), y,
8989
),
9090
combiner = c("median", "mean", "none")) {
9191
# Validate combiner
92-
combiner <- match.arg(combiner)
92+
combiner <- rlang::arg_match(combiner)
9393

9494
# Validate that x contains all distinct values
9595
if (any(duplicated(x))) {
@@ -189,7 +189,7 @@ detect_outlr_rm <- function(x = seq_along(y), y, n = 21,
189189

190190
# Calculate lower and upper thresholds and replacement value
191191
z <- z %>%
192-
epi_slide(fitted = median(y), before = floor((n - 1) / 2), after = ceiling((n - 1) / 2)) %>%
192+
epi_slide(fitted = median(y), .window_size = n, .align = "center") %>%
193193
dplyr::mutate(resid = y - fitted) %>%
194194
roll_iqr(
195195
n = n,
@@ -360,8 +360,7 @@ roll_iqr <- function(z, n, detection_multiplier, min_radius,
360360
z %>%
361361
epi_slide(
362362
roll_iqr = stats::IQR(resid),
363-
before = floor((n - 1) / 2),
364-
after = ceiling((n - 1) / 2)
363+
.window_size = n, .align = "center"
365364
) %>%
366365
dplyr::mutate(
367366
lower = pmax(

0 commit comments

Comments
 (0)