@@ -5,18 +5,25 @@ test_that("Column names can be passed with and without the tidy way", {
5
5
value = c(1000 , 2000 , 3000 , 4000 , 5000 , 6000 )
6
6
)
7
7
8
- newdata <- case_death_rate_subset %> % filter(geo_value %in% c(" ak" , " al" , " ar" , " as" , " az" , " ca" ))
8
+ pop_data2 <- pop_data %> % dplyr :: rename(geo_value = states )
9
+
10
+ newdata <- case_death_rate_subset %> %
11
+ filter(geo_value %in% c(" ak" , " al" , " ar" , " as" , " az" , " ca" ))
9
12
10
13
r1 <- epi_recipe(newdata ) %> %
11
- step_population_scaling(c(" case_rate" , " death_rate" ),
14
+ step_population_scaling(
15
+ case_rate , death_rate ,
12
16
df = pop_data ,
13
- df_pop_col = " value" , by = c(" geo_value" = " states" )
17
+ df_pop_col = " value" ,
18
+ by = c(" geo_value" = " states" )
14
19
)
15
20
16
21
r2 <- epi_recipe(newdata ) %> %
17
- step_population_scaling(case_rate , death_rate ,
18
- df = pop_data ,
19
- df_pop_col = " value" , by = c(" geo_value" = " states" )
22
+ step_population_scaling(
23
+ case_rate , death_rate ,
24
+ df = pop_data2 ,
25
+ df_pop_col = " value" ,
26
+ by = " geo_value"
20
27
)
21
28
22
29
prep1 <- prep(r1 , newdata )
@@ -56,9 +63,9 @@ test_that("Number of columns and column names returned correctly, Upper and lowe
56
63
suffix = " _rate"
57
64
)
58
65
59
- prep <- prep(r , newdata )
66
+ p <- prep(r , newdata )
60
67
61
- expect_silent( b <- bake(prep , newdata ) )
68
+ b <- bake(p , newdata )
62
69
expect_equal(ncol(b ), 7L )
63
70
expect_true(" case_rate" %in% colnames(b ))
64
71
expect_true(" death_rate" %in% colnames(b ))
@@ -75,15 +82,15 @@ test_that("Number of columns and column names returned correctly, Upper and lowe
75
82
create_new = FALSE
76
83
)
77
84
78
- expect_warning(prep <- prep(r , newdata ))
85
+ expect_warning(p <- prep(r , newdata ))
79
86
80
- expect_warning(b <- bake(prep , newdata ))
87
+ expect_warning(b <- bake(p , newdata ))
81
88
expect_equal(ncol(b ), 5L )
82
89
})
83
90
84
91
# # Postprocessing
85
92
test_that(" Postprocessing workflow works and values correct" , {
86
- jhu <- epiprocess :: jhu_csse_daily_subset %> %
93
+ jhu <- jhu_csse_daily_subset %> %
87
94
dplyr :: filter(time_value > " 2021-11-01" , geo_value %in% c(" ca" , " ny" )) %> %
88
95
dplyr :: select(geo_value , time_value , cases )
89
96
@@ -207,9 +214,17 @@ test_that("test joining by default columns", {
207
214
recipes :: step_naomit(recipes :: all_predictors()) %> %
208
215
recipes :: step_naomit(recipes :: all_outcomes(), skip = TRUE )
209
216
210
- expect_silent(prep(r , jhu ))
217
+ p <- prep(r , jhu )
218
+ b <- bake(p , new_data = NULL )
219
+ expect_named(
220
+ b ,
221
+ c(" geo_value" , " time_value" , " case_rate" , " case_rate_scaled" ,
222
+ paste0(" lag_" , c(0 ,7 ,14 ), " _case_rate_scaled" ),
223
+ " ahead_7_case_rate_scaled"
224
+ )
225
+ )
226
+
211
227
212
- expect_silent(bake(prep(r , jhu ), new_data = NULL ))
213
228
214
229
f <- frosting() %> %
215
230
layer_predict() %> %
@@ -221,13 +236,13 @@ test_that("test joining by default columns", {
221
236
df_pop_col = " values"
222
237
)
223
238
224
- expect_silent(
225
- wf <- epi_workflow(r , parsnip :: linear_reg()) %> %
226
- fit(jhu ) %> %
227
- add_frosting(f )
228
- )
239
+ wf <- epi_workflow(r , parsnip :: linear_reg()) %> %
240
+ fit(jhu ) %> %
241
+ add_frosting(f )
229
242
230
- expect_silent(forecast(wf ))
243
+ fc <- forecast(wf )
244
+ expect_named(fc , c(" geo_value" , " time_value" , " .pred" , " .pred_scaled" ))
245
+ expect_equal(fc $ .pred_scaled , fc $ .pred * c(1 / 20000 , 1 / 30000 ))
231
246
})
232
247
233
248
0 commit comments