From ff10f36369c0660a394ff5b3ebdbc7d3fb5ee2e9 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Thu, 27 Jun 2024 15:35:24 -0700 Subject: [PATCH 1/4] doc: fix step_lag_difference example --- R/step_lag_difference.R | 5 +++-- man/step_lag_difference.Rd | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/R/step_lag_difference.R b/R/step_lag_difference.R index 21878eaa7..9ee3c3567 100644 --- a/R/step_lag_difference.R +++ b/R/step_lag_difference.R @@ -16,11 +16,12 @@ #' @export #' @examples #' r <- epi_recipe(case_death_rate_subset) %>% -#' step_lag_difference(case_rate, death_rate, horizon = c(7, 14)) +#' step_lag_difference(case_rate, death_rate, horizon = c(7, 14)) %>% +#' step_epi_naomit() #' r #' #' r %>% -#' recipes::prep() %>% +#' recipes::prep(case_death_rate_subset) %>% #' recipes::bake(case_death_rate_subset) step_lag_difference <- function(recipe, diff --git a/man/step_lag_difference.Rd b/man/step_lag_difference.Rd index b06abe43c..9f1a5c96d 100644 --- a/man/step_lag_difference.Rd +++ b/man/step_lag_difference.Rd @@ -56,11 +56,12 @@ that will generate one or more new columns of derived data. } \examples{ r <- epi_recipe(case_death_rate_subset) \%>\% - step_lag_difference(case_rate, death_rate, horizon = c(7, 14)) + step_lag_difference(case_rate, death_rate, horizon = c(7, 14)) \%>\% + step_epi_naomit() r r \%>\% - recipes::prep() \%>\% + recipes::prep(case_death_rate_subset) \%>\% recipes::bake(case_death_rate_subset) } \seealso{ From c7ce21441a18d2611377a10e3e37d1f64152cdc9 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Thu, 27 Jun 2024 15:46:28 -0700 Subject: [PATCH 2/4] Update R/step_lag_difference.R Co-authored-by: Daniel McDonald --- R/step_lag_difference.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/step_lag_difference.R b/R/step_lag_difference.R index 9ee3c3567..e954bd9a0 100644 --- a/R/step_lag_difference.R +++ b/R/step_lag_difference.R @@ -21,8 +21,8 @@ #' r #' #' r %>% -#' recipes::prep(case_death_rate_subset) %>% -#' recipes::bake(case_death_rate_subset) +#' prep(case_death_rate_subset) %>% +#' bake(case_death_rate_subset) step_lag_difference <- function(recipe, ..., From ff95a70f4d3f41a07b0d6756c6c181d01085b990 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Thu, 27 Jun 2024 15:49:08 -0700 Subject: [PATCH 3/4] doc: lint step_growth_rate example --- R/step_growth_rate.R | 4 ++-- man/step_growth_rate.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/step_growth_rate.R b/R/step_growth_rate.R index 74cfff284..e5edb18d4 100644 --- a/R/step_growth_rate.R +++ b/R/step_growth_rate.R @@ -39,8 +39,8 @@ #' r #' #' r %>% -#' recipes::prep() %>% -#' recipes::bake(case_death_rate_subset) +#' prep(case_death_rate_subset) %>% +#' bake(case_death_rate_subset) step_growth_rate <- function(recipe, ..., diff --git a/man/step_growth_rate.Rd b/man/step_growth_rate.Rd index b409135b1..46d8b92f6 100644 --- a/man/step_growth_rate.Rd +++ b/man/step_growth_rate.Rd @@ -88,8 +88,8 @@ r <- epi_recipe(case_death_rate_subset) \%>\% r r \%>\% - recipes::prep() \%>\% - recipes::bake(case_death_rate_subset) + prep(case_death_rate_subset) \%>\% + bake(case_death_rate_subset) } \seealso{ Other row operation steps: From 9fd37ca27140177c89a5bd0b8f56210f902fa5c1 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Thu, 27 Jun 2024 16:53:30 -0700 Subject: [PATCH 4/4] doc: lint a few more examples --- man/step_lag_difference.Rd | 4 +- tests/testthat/test-check_enough_train_data.R | 44 +++++++++---------- tests/testthat/test-step_training_window.R | 32 +++++++------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/man/step_lag_difference.Rd b/man/step_lag_difference.Rd index 9f1a5c96d..123265ea6 100644 --- a/man/step_lag_difference.Rd +++ b/man/step_lag_difference.Rd @@ -61,8 +61,8 @@ r <- epi_recipe(case_death_rate_subset) \%>\% r r \%>\% - recipes::prep(case_death_rate_subset) \%>\% - recipes::bake(case_death_rate_subset) + prep(case_death_rate_subset) \%>\% + bake(case_death_rate_subset) } \seealso{ Other row operation steps: diff --git a/tests/testthat/test-check_enough_train_data.R b/tests/testthat/test-check_enough_train_data.R index 02b9e35e4..502ea06f1 100644 --- a/tests/testthat/test-check_enough_train_data.R +++ b/tests/testthat/test-check_enough_train_data.R @@ -19,23 +19,23 @@ test_that("check_enough_train_data works on pooled data", { expect_no_error( epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = 2 * n, drop_na = FALSE) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = NULL) + prep(toy_epi_df) %>% + bake(new_data = NULL) ) # Check both column don't have enough data expect_error( epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = 2 * n + 1, drop_na = FALSE) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = NULL), + prep(toy_epi_df) %>% + bake(new_data = NULL), regexp = "The following columns don't have enough data" ) # Check drop_na works expect_error( epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = 2 * n - 1, drop_na = TRUE) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = NULL) + prep(toy_epi_df) %>% + bake(new_data = NULL) ) }) @@ -44,23 +44,23 @@ test_that("check_enough_train_data works on unpooled data", { expect_no_error( epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = n, epi_keys = "geo_value", drop_na = FALSE) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = NULL) + prep(toy_epi_df) %>% + bake(new_data = NULL) ) # Check one column don't have enough data expect_error( epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = n + 1, epi_keys = "geo_value", drop_na = FALSE) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = NULL), + prep(toy_epi_df) %>% + bake(new_data = NULL), regexp = "The following columns don't have enough data" ) # Check drop_na works expect_error( epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = 2 * n - 3, epi_keys = "geo_value", drop_na = TRUE) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = NULL) + prep(toy_epi_df) %>% + bake(new_data = NULL) ) }) @@ -68,8 +68,8 @@ test_that("check_enough_train_data outputs the correct recipe values", { expect_no_error( p <- epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = 2 * n - 2) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = NULL) + prep(toy_epi_df) %>% + bake(new_data = NULL) ) expect_equal(nrow(p), 2 * n) @@ -93,15 +93,15 @@ test_that("check_enough_train_data only checks train data", { expect_no_error( epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = n - 2, epi_keys = "geo_value") %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = toy_test_data) + prep(toy_epi_df) %>% + bake(new_data = toy_test_data) ) # Same thing, but skip = FALSE expect_no_error( epi_recipe(toy_epi_df) %>% check_enough_train_data(y, n = n - 2, epi_keys = "geo_value", skip = FALSE) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = toy_test_data) + prep(toy_epi_df) %>% + bake(new_data = toy_test_data) ) }) @@ -111,14 +111,14 @@ test_that("check_enough_train_data works with all_predictors() downstream of con epi_recipe(toy_epi_df) %>% step_epi_lag(x, lag = c(1, 2)) %>% check_enough_train_data(all_predictors(), y, n = 2 * n - 6) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = NULL) + prep(toy_epi_df) %>% + bake(new_data = NULL) ) expect_error( epi_recipe(toy_epi_df) %>% step_epi_lag(x, lag = c(1, 2)) %>% check_enough_train_data(all_predictors(), y, n = 2 * n - 5) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = NULL) + prep(toy_epi_df) %>% + bake(new_data = NULL) ) }) diff --git a/tests/testthat/test-step_training_window.R b/tests/testthat/test-step_training_window.R index 9ec1e5982..f49668a40 100644 --- a/tests/testthat/test-step_training_window.R +++ b/tests/testthat/test-step_training_window.R @@ -11,8 +11,8 @@ toy_epi_df <- tibble::tibble( test_that("step_training_window works with default n_recent", { p <- epi_recipe(y ~ x, data = toy_epi_df) %>% step_training_window() %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = NULL) + prep(toy_epi_df) %>% + bake(new_data = NULL) expect_equal(nrow(p), 100L) expect_equal(ncol(p), 4L) @@ -28,8 +28,8 @@ test_that("step_training_window works with default n_recent", { test_that("step_training_window works with specified n_recent", { p2 <- epi_recipe(y ~ x, data = toy_epi_df) %>% step_training_window(n_recent = 5) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = NULL) + prep(toy_epi_df) %>% + bake(new_data = NULL) expect_equal(nrow(p2), 10L) expect_equal(ncol(p2), 4L) @@ -48,8 +48,8 @@ test_that("step_training_window does not proceed with specified new_data", { # testing data. p3 <- epi_recipe(y ~ x, data = toy_epi_df) %>% step_training_window(n_recent = 3) %>% - recipes::prep(toy_epi_df) %>% - recipes::bake(new_data = toy_epi_df[1:10, ]) + prep(toy_epi_df) %>% + bake(new_data = toy_epi_df[1:10, ]) expect_equal(nrow(p3), 10L) expect_equal(ncol(p3), 4L) @@ -78,8 +78,8 @@ test_that("step_training_window works with multiple keys", { p4 <- epi_recipe(y ~ x, data = toy_epi_df2) %>% step_training_window(n_recent = 3) %>% - recipes::prep(toy_epi_df2) %>% - recipes::bake(new_data = NULL) + prep(toy_epi_df2) %>% + bake(new_data = NULL) expect_equal(nrow(p4), 12L) expect_equal(ncol(p4), 5L) @@ -112,20 +112,20 @@ test_that("step_training_window and step_naomit interact", { e1 <- epi_recipe(y ~ x, data = tib) %>% step_training_window(n_recent = 3) %>% - recipes::prep(tib) %>% - recipes::bake(new_data = NULL) + prep(tib) %>% + bake(new_data = NULL) e2 <- epi_recipe(y ~ x, data = tib) %>% - recipes::step_naomit() %>% + step_naomit() %>% step_training_window(n_recent = 3) %>% - recipes::prep(tib) %>% - recipes::bake(new_data = NULL) + prep(tib) %>% + bake(new_data = NULL) e3 <- epi_recipe(y ~ x, data = tib) %>% step_training_window(n_recent = 3) %>% - recipes::step_naomit() %>% - recipes::prep(tib) %>% - recipes::bake(new_data = NULL) + step_naomit() %>% + prep(tib) %>% + bake(new_data = NULL) expect_identical(e1, e2) expect_identical(e2, e3)