Skip to content

Commit 41aa2f1

Browse files
committed
adjustments for epiprocess 0.10.4 growth_rate
1 parent 7a103fa commit 41aa2f1

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

R/step_growth_rate.R

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
#' being removed from the data. Alternatively, you could specify arbitrary
2323
#' large values, or perhaps zero. Setting this argument to `NULL` will result
2424
#' in no replacement.
25-
#' @param additional_gr_args_list A list of additional arguments used by
26-
#' [epiprocess::growth_rate()]. All `...` arguments may be passed here along
27-
#' with `dup_rm` and `na_rm`.
25+
#' @inheritParams epiprocess::growth_rate
2826
#' @template step-return
2927
#'
3028
#'
@@ -46,11 +44,11 @@ step_growth_rate <-
4644
horizon = 7,
4745
method = c("rel_change", "linear_reg"),
4846
log_scale = FALSE,
47+
na_rm = TRUE,
4948
replace_Inf = NA,
5049
prefix = "gr_",
5150
skip = FALSE,
52-
id = rand_id("growth_rate"),
53-
additional_gr_args_list = list()) {
51+
id = rand_id("growth_rate")) {
5452
if (!is_epi_recipe(recipe)) {
5553
cli_abort("This recipe step can only operate on an {.cls epi_recipe}.")
5654
}
@@ -63,15 +61,7 @@ step_growth_rate <-
6361
}
6462
arg_is_chr(role)
6563
arg_is_chr_scalar(prefix, id)
66-
arg_is_lgl_scalar(log_scale, skip)
67-
68-
69-
if (!is.list(additional_gr_args_list)) {
70-
cli_abort(c(
71-
"`additional_gr_args_list` must be a {.cls list}.",
72-
i = "See `?epiprocess::growth_rate` for available options."
73-
))
74-
}
64+
arg_is_lgl_scalar(log_scale, skip, na_rm)
7565

7666
recipes::add_step(
7767
recipe,
@@ -82,13 +72,13 @@ step_growth_rate <-
8272
horizon = horizon,
8373
method = method,
8474
log_scale = log_scale,
75+
na_rm = na_rm,
8576
replace_Inf = replace_Inf,
8677
prefix = prefix,
8778
keys = key_colnames(recipe),
8879
columns = NULL,
8980
skip = skip,
90-
id = id,
91-
additional_gr_args_list = additional_gr_args_list
81+
id = id
9282
)
9383
)
9484
}
@@ -101,13 +91,13 @@ step_growth_rate_new <-
10191
horizon,
10292
method,
10393
log_scale,
94+
na_rm,
10495
replace_Inf,
10596
prefix,
10697
keys,
10798
columns,
10899
skip,
109-
id,
110-
additional_gr_args_list) {
100+
id) {
111101
recipes::step(
112102
subclass = "growth_rate",
113103
terms = terms,
@@ -116,13 +106,13 @@ step_growth_rate_new <-
116106
horizon = horizon,
117107
method = method,
118108
log_scale = log_scale,
109+
na_rm = na_rm,
119110
replace_Inf = replace_Inf,
120111
prefix = prefix,
121112
keys = keys,
122113
columns = columns,
123114
skip = skip,
124-
id = id,
125-
additional_gr_args_list = additional_gr_args_list
115+
id = id
126116
)
127117
}
128118

@@ -137,13 +127,13 @@ prep.step_growth_rate <- function(x, training, info = NULL, ...) {
137127
horizon = x$horizon,
138128
method = x$method,
139129
log_scale = x$log_scale,
130+
na_rm = x$na_rm,
140131
replace_Inf = x$replace_Inf,
141132
prefix = x$prefix,
142133
keys = x$keys,
143134
columns = recipes::recipes_eval_select(x$terms, training, info),
144135
skip = x$skip,
145-
id = x$id,
146-
additional_gr_args_list = x$additional_gr_args_list
136+
id = x$id
147137
)
148138
}
149139

@@ -177,10 +167,12 @@ bake.step_growth_rate <- function(object, new_data, ...) {
177167
across(
178168
all_of(object$columns),
179169
~ epiprocess::growth_rate(
180-
time_value, .x,
170+
.x,
171+
x = time_value,
181172
method = object$method,
182-
h = object$horizon, log_scale = object$log_scale,
183-
!!!object$additional_gr_args_list
173+
h = object$horizon,
174+
log_scale = object$log_scale,
175+
na_rm = object$na_rm
184176
),
185177
.names = "{object$prefix}{object$horizon}_{object$method}_{.col}"
186178
)

tests/testthat/_snaps/step_growth_rate.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,18 @@
8989
---
9090

9191
Code
92-
step_growth_rate(r, value, skip = 1)
92+
step_growth_rate(r, value, na_rm = 1)
9393
Condition
9494
Error in `step_growth_rate()`:
95-
! `skip` must be a scalar of type <logical>.
95+
! `na_rm` must be a scalar of type <logical>.
9696

9797
---
9898

9999
Code
100-
step_growth_rate(r, value, additional_gr_args_list = 1:5)
100+
step_growth_rate(r, value, skip = 1)
101101
Condition
102102
Error in `step_growth_rate()`:
103-
! `additional_gr_args_list` must be a <list>.
104-
i See `?epiprocess::growth_rate` for available options.
103+
! `skip` must be a scalar of type <logical>.
105104

106105
---
107106

tests/testthat/test-step_growth_rate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ test_that("step_growth_rate validates arguments", {
1616
expect_snapshot(error = TRUE, step_growth_rate(r, value, prefix = 1))
1717
expect_snapshot(error = TRUE, step_growth_rate(r, value, id = 1))
1818
expect_snapshot(error = TRUE, step_growth_rate(r, value, log_scale = 1))
19+
expect_snapshot(error = TRUE, step_growth_rate(r, value, na_rm = 1))
1920
expect_snapshot(error = TRUE, step_growth_rate(r, value, skip = 1))
20-
expect_snapshot(error = TRUE, step_growth_rate(r, value, additional_gr_args_list = 1:5))
2121
expect_snapshot(error = TRUE, step_growth_rate(r, value, replace_Inf = "c"))
2222
expect_snapshot(error = TRUE, step_growth_rate(r, value, replace_Inf = c(1, 2)))
2323
expect_silent(step_growth_rate(r, value, replace_Inf = NULL))

0 commit comments

Comments
 (0)