Skip to content

Commit 55e0808

Browse files
committed
include a test for bake
1 parent ad3cb38 commit 55e0808

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/testthat/test-bake-method.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
test_that("bake method works in all cases", {
2+
edf <- case_death_rate_subset %>%
3+
filter(time_value > "2021-11-01", geo_value %in% c("ak", "ca", "ny"))
4+
r <- epi_recipe(jhu) %>%
5+
step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
6+
step_epi_ahead(death_rate, ahead = 7)
7+
8+
r2 <- epi_recipe(jhu) %>%
9+
step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
10+
step_epi_ahead(death_rate, ahead = 7) %>%
11+
step_epi_naomit()
12+
13+
b_null <- bake(prep(r, edf), NULL)
14+
b_train <- bake(prep(r, edf), edf)
15+
expect_s3_class(b_null, "epi_df")
16+
expect_identical(b_null, b_train)
17+
18+
b_baked <- bake(prep(r2, edf), edf) # leaves rows with NA in the response
19+
# doesn't (because we "juice", so skip doesn't apply)
20+
b_juiced <- bake(prep(r2, edf), NULL)
21+
expect_equal(nrow(b_juiced), sum(complete.cases(b_train)))
22+
expect_equal(nrow(b_baked), sum(complete.cases(b_train)) + 3 * 7)
23+
24+
# check that the {recipes} behaves
25+
expect_s3_class(bake(prep(r, edf), NULL, composition = "tibble"), "tbl_df")
26+
expect_s3_class(bake(prep(r, edf), NULL, composition = "data.frame"), "data.frame")
27+
# can't be a matrix because time_value/geo_value aren't numeric
28+
expect_error(bake(prep(r, edf), NULL, composition = "matrix"))
29+
})

0 commit comments

Comments
 (0)