Skip to content

Commit 54ee888

Browse files
authored
refactor: training_window2 -> epi_training_window (#183)
1 parent 7aee9bd commit 54ee888

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

R/forecasters/epipredict_utilities.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ arx_preprocess <- function(preproc, outcome, predictors, args_list) {
3131
preproc %<>%
3232
step_epi_ahead(!!outcome, ahead = args_list$ahead) %>%
3333
step_epi_naomit() %>%
34-
step_training_window2(
34+
step_epi_training_window(
3535
n_recent = args_list$n_training,
3636
seasonal = args_list$seasonal_window,
3737
seasonal_backward_window = args_list$seasonal_backward_window,

R/new_epipredict_steps/step_training_window.R

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Limits the size of the training window to the most recent observations
22
#'
3-
#' `step_training_window2` creates a *specification* of a recipe step that
3+
#' `step_epi_training_window` creates a *specification* of a recipe step that
44
#' limits the size of the training window to the `n_recent` most recent
55
#' observations in `time_value` per group, where the groups are formed
66
#' based on the remaining `epi_keys`.
@@ -40,32 +40,32 @@
4040
#' as_epi_df()
4141
#'
4242
#' epi_recipe(y ~ x, data = tib) %>%
43-
#' step_training_window2(n_recent = 3) %>%
43+
#' step_epi_training_window(n_recent = 3) %>%
4444
#' prep(tib) %>%
4545
#' bake(new_data = NULL)
4646
#'
4747
#' epi_recipe(y ~ x, data = tib) %>%
4848
#' step_epi_naomit() %>%
49-
#' step_training_window2(n_recent = 3) %>%
49+
#' step_epi_training_window(n_recent = 3) %>%
5050
#' prep(tib) %>%
5151
#' bake(new_data = NULL)
52-
step_training_window2 <-
52+
step_epi_training_window <-
5353
function(recipe,
5454
role = NA,
5555
n_recent = 50,
5656
seasonal = FALSE,
5757
seasonal_forward_window = 14,
5858
seasonal_backward_window = 35,
5959
epi_keys = NULL,
60-
id = rand_id("training_window2")) {
60+
id = rand_id("epi_training_window")) {
6161
epipredict:::arg_is_scalar(n_recent, id, seasonal, seasonal_forward_window, seasonal_backward_window)
6262
epipredict:::arg_is_pos(n_recent, seasonal_forward_window, seasonal_backward_window)
6363
if (is.finite(n_recent)) epipredict:::arg_is_pos_int(n_recent)
6464
epipredict:::arg_is_chr(id)
6565
epipredict:::arg_is_chr(epi_keys, allow_null = TRUE)
6666
add_step(
6767
recipe,
68-
step_training_window2_new(
68+
step_epi_training_window_new(
6969
role = role,
7070
trained = FALSE,
7171
n_recent = n_recent,
@@ -79,10 +79,10 @@ step_training_window2 <-
7979
)
8080
}
8181

82-
step_training_window2_new <-
82+
step_epi_training_window_new <-
8383
function(role, trained, n_recent, seasonal, seasonal_forward_window, seasonal_backward_window, epi_keys, skip, id) {
8484
step(
85-
subclass = "training_window2",
85+
subclass = "epi_training_window",
8686
role = role,
8787
trained = trained,
8888
n_recent = n_recent,
@@ -96,13 +96,13 @@ step_training_window2_new <-
9696
}
9797

9898
#' @export
99-
prep.step_training_window2 <- function(x, training, info = NULL, ...) {
99+
prep.step_epi_training_window <- function(x, training, info = NULL, ...) {
100100
ekt <- epipredict:::epi_keys_only(training)
101101
ek <- x$epi_keys %||% ekt %||% character(0L)
102102

103103
hardhat::validate_column_names(training, ek)
104104

105-
step_training_window2_new(
105+
step_epi_training_window_new(
106106
role = x$role,
107107
trained = TRUE,
108108
n_recent = x$n_recent,
@@ -116,7 +116,7 @@ prep.step_training_window2 <- function(x, training, info = NULL, ...) {
116116
}
117117

118118
#' @export
119-
bake.step_training_window2 <- function(object, new_data, ...) {
119+
bake.step_epi_training_window <- function(object, new_data, ...) {
120120
hardhat::validate_column_names(new_data, object$epi_keys)
121121

122122
if (object$n_recent < Inf) {
@@ -155,7 +155,7 @@ bake.step_training_window2 <- function(object, new_data, ...) {
155155
}
156156

157157
#' @export
158-
print.step_training_window2 <-
158+
print.step_epi_training_window <-
159159
function(x, width = max(20, options()$width - 30), ...) {
160160
if (x$seasonal) {
161161
title <- "# of seasonal observations per key limited to:"

tests/testthat/test-step-training-window.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ data <- tribble(
1212
bind_rows((.) %>% filter(geo_value == "ca") %>% mutate(time_value = time_value - 365)) %>%
1313
as_epi_df()
1414

15-
# debugonce(bake.step_training_window2)
15+
# debugonce(bake.step_epi_training_window)
1616
epi_recipe(data) %>%
17-
step_training_window2(seasonal_backward_window = 5, seasonal_forward_window = 3, seasonal = TRUE) %>%
17+
step_epi_training_window(seasonal_backward_window = 5, seasonal_forward_window = 3, seasonal = TRUE) %>%
1818
prep(data) %>%
1919
bake(new_data = NULL)
2020

0 commit comments

Comments
 (0)