Skip to content

Commit 14e3708

Browse files
authored
Merge pull request #349 from cmu-delphi/ds/step-lag-example
doc: fix step_lag_difference example
2 parents abe8805 + 9fd37ca commit 14e3708

6 files changed

+50
-48
lines changed

R/step_growth_rate.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
#' r
4040
#'
4141
#' r %>%
42-
#' recipes::prep() %>%
43-
#' recipes::bake(case_death_rate_subset)
42+
#' prep(case_death_rate_subset) %>%
43+
#' bake(case_death_rate_subset)
4444
step_growth_rate <-
4545
function(recipe,
4646
...,

R/step_lag_difference.R

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
#' @export
1717
#' @examples
1818
#' r <- epi_recipe(case_death_rate_subset) %>%
19-
#' step_lag_difference(case_rate, death_rate, horizon = c(7, 14))
19+
#' step_lag_difference(case_rate, death_rate, horizon = c(7, 14)) %>%
20+
#' step_epi_naomit()
2021
#' r
2122
#'
2223
#' r %>%
23-
#' recipes::prep() %>%
24-
#' recipes::bake(case_death_rate_subset)
24+
#' prep(case_death_rate_subset) %>%
25+
#' bake(case_death_rate_subset)
2526
step_lag_difference <-
2627
function(recipe,
2728
...,

man/step_growth_rate.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/step_lag_difference.Rd

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-check_enough_train_data.R

+22-22
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ test_that("check_enough_train_data works on pooled data", {
1919
expect_no_error(
2020
epi_recipe(toy_epi_df) %>%
2121
check_enough_train_data(x, y, n = 2 * n, drop_na = FALSE) %>%
22-
recipes::prep(toy_epi_df) %>%
23-
recipes::bake(new_data = NULL)
22+
prep(toy_epi_df) %>%
23+
bake(new_data = NULL)
2424
)
2525
# Check both column don't have enough data
2626
expect_error(
2727
epi_recipe(toy_epi_df) %>%
2828
check_enough_train_data(x, y, n = 2 * n + 1, drop_na = FALSE) %>%
29-
recipes::prep(toy_epi_df) %>%
30-
recipes::bake(new_data = NULL),
29+
prep(toy_epi_df) %>%
30+
bake(new_data = NULL),
3131
regexp = "The following columns don't have enough data"
3232
)
3333
# Check drop_na works
3434
expect_error(
3535
epi_recipe(toy_epi_df) %>%
3636
check_enough_train_data(x, y, n = 2 * n - 1, drop_na = TRUE) %>%
37-
recipes::prep(toy_epi_df) %>%
38-
recipes::bake(new_data = NULL)
37+
prep(toy_epi_df) %>%
38+
bake(new_data = NULL)
3939
)
4040
})
4141

@@ -44,32 +44,32 @@ test_that("check_enough_train_data works on unpooled data", {
4444
expect_no_error(
4545
epi_recipe(toy_epi_df) %>%
4646
check_enough_train_data(x, y, n = n, epi_keys = "geo_value", drop_na = FALSE) %>%
47-
recipes::prep(toy_epi_df) %>%
48-
recipes::bake(new_data = NULL)
47+
prep(toy_epi_df) %>%
48+
bake(new_data = NULL)
4949
)
5050
# Check one column don't have enough data
5151
expect_error(
5252
epi_recipe(toy_epi_df) %>%
5353
check_enough_train_data(x, y, n = n + 1, epi_keys = "geo_value", drop_na = FALSE) %>%
54-
recipes::prep(toy_epi_df) %>%
55-
recipes::bake(new_data = NULL),
54+
prep(toy_epi_df) %>%
55+
bake(new_data = NULL),
5656
regexp = "The following columns don't have enough data"
5757
)
5858
# Check drop_na works
5959
expect_error(
6060
epi_recipe(toy_epi_df) %>%
6161
check_enough_train_data(x, y, n = 2 * n - 3, epi_keys = "geo_value", drop_na = TRUE) %>%
62-
recipes::prep(toy_epi_df) %>%
63-
recipes::bake(new_data = NULL)
62+
prep(toy_epi_df) %>%
63+
bake(new_data = NULL)
6464
)
6565
})
6666

6767
test_that("check_enough_train_data outputs the correct recipe values", {
6868
expect_no_error(
6969
p <- epi_recipe(toy_epi_df) %>%
7070
check_enough_train_data(x, y, n = 2 * n - 2) %>%
71-
recipes::prep(toy_epi_df) %>%
72-
recipes::bake(new_data = NULL)
71+
prep(toy_epi_df) %>%
72+
bake(new_data = NULL)
7373
)
7474

7575
expect_equal(nrow(p), 2 * n)
@@ -93,15 +93,15 @@ test_that("check_enough_train_data only checks train data", {
9393
expect_no_error(
9494
epi_recipe(toy_epi_df) %>%
9595
check_enough_train_data(x, y, n = n - 2, epi_keys = "geo_value") %>%
96-
recipes::prep(toy_epi_df) %>%
97-
recipes::bake(new_data = toy_test_data)
96+
prep(toy_epi_df) %>%
97+
bake(new_data = toy_test_data)
9898
)
9999
# Same thing, but skip = FALSE
100100
expect_no_error(
101101
epi_recipe(toy_epi_df) %>%
102102
check_enough_train_data(y, n = n - 2, epi_keys = "geo_value", skip = FALSE) %>%
103-
recipes::prep(toy_epi_df) %>%
104-
recipes::bake(new_data = toy_test_data)
103+
prep(toy_epi_df) %>%
104+
bake(new_data = toy_test_data)
105105
)
106106
})
107107

@@ -111,14 +111,14 @@ test_that("check_enough_train_data works with all_predictors() downstream of con
111111
epi_recipe(toy_epi_df) %>%
112112
step_epi_lag(x, lag = c(1, 2)) %>%
113113
check_enough_train_data(all_predictors(), y, n = 2 * n - 6) %>%
114-
recipes::prep(toy_epi_df) %>%
115-
recipes::bake(new_data = NULL)
114+
prep(toy_epi_df) %>%
115+
bake(new_data = NULL)
116116
)
117117
expect_error(
118118
epi_recipe(toy_epi_df) %>%
119119
step_epi_lag(x, lag = c(1, 2)) %>%
120120
check_enough_train_data(all_predictors(), y, n = 2 * n - 5) %>%
121-
recipes::prep(toy_epi_df) %>%
122-
recipes::bake(new_data = NULL)
121+
prep(toy_epi_df) %>%
122+
bake(new_data = NULL)
123123
)
124124
})

tests/testthat/test-step_training_window.R

+16-16
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ toy_epi_df <- tibble::tibble(
1111
test_that("step_training_window works with default n_recent", {
1212
p <- epi_recipe(y ~ x, data = toy_epi_df) %>%
1313
step_training_window() %>%
14-
recipes::prep(toy_epi_df) %>%
15-
recipes::bake(new_data = NULL)
14+
prep(toy_epi_df) %>%
15+
bake(new_data = NULL)
1616

1717
expect_equal(nrow(p), 100L)
1818
expect_equal(ncol(p), 4L)
@@ -28,8 +28,8 @@ test_that("step_training_window works with default n_recent", {
2828
test_that("step_training_window works with specified n_recent", {
2929
p2 <- epi_recipe(y ~ x, data = toy_epi_df) %>%
3030
step_training_window(n_recent = 5) %>%
31-
recipes::prep(toy_epi_df) %>%
32-
recipes::bake(new_data = NULL)
31+
prep(toy_epi_df) %>%
32+
bake(new_data = NULL)
3333

3434
expect_equal(nrow(p2), 10L)
3535
expect_equal(ncol(p2), 4L)
@@ -48,8 +48,8 @@ test_that("step_training_window does not proceed with specified new_data", {
4848
# testing data.
4949
p3 <- epi_recipe(y ~ x, data = toy_epi_df) %>%
5050
step_training_window(n_recent = 3) %>%
51-
recipes::prep(toy_epi_df) %>%
52-
recipes::bake(new_data = toy_epi_df[1:10, ])
51+
prep(toy_epi_df) %>%
52+
bake(new_data = toy_epi_df[1:10, ])
5353

5454
expect_equal(nrow(p3), 10L)
5555
expect_equal(ncol(p3), 4L)
@@ -78,8 +78,8 @@ test_that("step_training_window works with multiple keys", {
7878

7979
p4 <- epi_recipe(y ~ x, data = toy_epi_df2) %>%
8080
step_training_window(n_recent = 3) %>%
81-
recipes::prep(toy_epi_df2) %>%
82-
recipes::bake(new_data = NULL)
81+
prep(toy_epi_df2) %>%
82+
bake(new_data = NULL)
8383

8484
expect_equal(nrow(p4), 12L)
8585
expect_equal(ncol(p4), 5L)
@@ -112,20 +112,20 @@ test_that("step_training_window and step_naomit interact", {
112112

113113
e1 <- epi_recipe(y ~ x, data = tib) %>%
114114
step_training_window(n_recent = 3) %>%
115-
recipes::prep(tib) %>%
116-
recipes::bake(new_data = NULL)
115+
prep(tib) %>%
116+
bake(new_data = NULL)
117117

118118
e2 <- epi_recipe(y ~ x, data = tib) %>%
119-
recipes::step_naomit() %>%
119+
step_naomit() %>%
120120
step_training_window(n_recent = 3) %>%
121-
recipes::prep(tib) %>%
122-
recipes::bake(new_data = NULL)
121+
prep(tib) %>%
122+
bake(new_data = NULL)
123123

124124
e3 <- epi_recipe(y ~ x, data = tib) %>%
125125
step_training_window(n_recent = 3) %>%
126-
recipes::step_naomit() %>%
127-
recipes::prep(tib) %>%
128-
recipes::bake(new_data = NULL)
126+
step_naomit() %>%
127+
prep(tib) %>%
128+
bake(new_data = NULL)
129129

130130
expect_identical(e1, e2)
131131
expect_identical(e2, e3)

0 commit comments

Comments
 (0)