Skip to content

Commit

Permalink
doc: lint a few more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dshemetov committed Jun 27, 2024
1 parent ff95a70 commit 9fd37ca
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions man/step_lag_difference.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 22 additions & 22 deletions tests/testthat/test-check_enough_train_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
})

Expand All @@ -44,32 +44,32 @@ 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)
)
})

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)
Expand All @@ -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)
)
})

Expand All @@ -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)
)
})
32 changes: 16 additions & 16 deletions tests/testthat/test-step_training_window.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9fd37ca

Please sign in to comment.