Skip to content

Commit fb030b5

Browse files
committed
update epi_keys_mold and tests to handle additional keys
1 parent d66168d commit fb030b5

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

R/epi_keys.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ epi_keys.recipe <- function(x) {
2929
epi_keys_mold <- function(mold) {
3030
keys <- c("time_value", "geo_value", "key")
3131
molded_names <- names(mold$extras$roles)
32+
3233
mold_keys <- map(mold$extras$roles[molded_names %in% keys], names)
33-
unname(unlist(mold_keys))
34+
unlist(unname(mold_keys))
3435
}
3536

tests/testthat/test-epi_keys.R

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,19 @@ test_that("epi_keys_mold extracts time_value and geo_value, but not raw",{
3232
})
3333

3434
test_that("epi_keys_mold extracts additional keys when they are present", {
35-
my_data <- tibble::tibble(
36-
geo_value = rep(c("ca", "fl", "pa"), each = 3),
37-
time_value = rep(seq(as.Date("2020-06-01"), as.Date("2020-06-03"),
38-
by = "day"), length.out = length(geo_value)),
39-
pol = rep(c("blue", "swing", "swing"), each = 3), # extra key
40-
state = rep(c("ca", "fl", "pa"), each = 3), # extra key
41-
value = 1:length(geo_value) + 0.01 * rnorm(length(geo_value))
42-
) %>%
43-
epiprocess::as_epi_df(additional_metadata = list(other_keys = c("state", "pol")))
44-
35+
my_data <- case_death_rate_subset %>%
36+
sample_n(6) %>%
37+
tsibble::as_tsibble() %>% # add 2 extra keys
38+
mutate(state = rep("MA", 6), pol = rep("blue", 6)) %>%
39+
as_epi_df(additional_metadata = list(other_keys=c("state", "pol")))
40+
4541
my_recipe <- epi_recipe(my_data) %>%
46-
step_epi_ahead(value , ahead = 7) %>%
42+
step_epi_ahead(death_rate , ahead = 7) %>%
4743
step_epi_naomit()
4844

4945
my_workflow <- epi_workflow(my_recipe, linear_reg()) %>% fit(my_data)
5046

51-
expect_setequal(
52-
epi_keys_mold(my_workflow$pre$mold),
47+
expect_equal(
48+
epi_keys_mold(my_workflow$pre$mold),
5349
c("time_value", "geo_value", "state", "pol"))
5450
})

0 commit comments

Comments
 (0)