Skip to content

Commit 039e714

Browse files
committed
styler has opinions
1 parent 22b52dd commit 039e714

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

R/utils-shift.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ adjust_latency <- function(object, new_data) {
4343
time_type <- attributes(new_data)$metadata$time_type
4444

4545
if ((grepl("day", time_type) && (shift_amount >= 10)) ||
46-
(grepl("week", time_type) && (shift_amount >= 4))||
47-
((time_type == "yearmonth") && (shift_amount >=2)) ||
48-
((time_type == "yearquarter") && (shift_amount >= 1)) ||
49-
((time_type == "year") && (shift_amount >= 1))) {
46+
(grepl("week", time_type) && (shift_amount >= 4)) ||
47+
((time_type == "yearmonth") && (shift_amount >= 2)) ||
48+
((time_type == "yearquarter") && (shift_amount >= 1)) ||
49+
((time_type == "year") && (shift_amount >= 1))) {
5050
cli::cli_warn(c(
51-
"!" = glue::glue("The ahead has been adjusted by {shift_amount}, ",
52-
"which is questionable for it's `time_type` of ",
53-
"{time_type}"),
51+
"!" = glue::glue(
52+
"The ahead has been adjusted by {shift_amount}, ",
53+
"which is questionable for it's `time_type` of ",
54+
"{time_type}"
55+
),
5456
"i" = "input ahead: {ahead}",
5557
"i" = "shifted ahead: {effective_ahead}",
5658
"i" = "max_time = {max_time} -> as_of = {as_of}"

tests/testthat/test-population_scaling.R

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,22 @@ test_that("Postprocessing to get cases from case rate", {
207207

208208

209209
test_that("test joining by default columns", {
210-
211210
jhu <- case_death_rate_subset %>%
212211
dplyr::filter(time_value > "2021-11-01", geo_value %in% c("ca", "ny")) %>%
213212
dplyr::select(geo_value, time_value, case_rate)
214213

215-
reverse_pop_data = data.frame(geo_value = c("ca", "ny"),
216-
values = c(1/20000, 1/30000))
214+
reverse_pop_data <- data.frame(
215+
geo_value = c("ca", "ny"),
216+
values = c(1 / 20000, 1 / 30000)
217+
)
217218

218219
r <- epi_recipe(jhu) %>%
219220
step_population_scaling(case_rate,
220-
df = reverse_pop_data,
221-
df_pop_col = "values",
222-
by = NULL,
223-
suffix = "_scaled") %>%
221+
df = reverse_pop_data,
222+
df_pop_col = "values",
223+
by = NULL,
224+
suffix = "_scaled"
225+
) %>%
224226
step_epi_lag(case_rate_scaled, lag = c(0, 7, 14)) %>% # cases
225227
step_epi_ahead(case_rate_scaled, ahead = 7, role = "outcome") %>% # cases
226228
recipes::step_naomit(recipes::all_predictors()) %>%
@@ -234,20 +236,28 @@ test_that("test joining by default columns", {
234236
layer_predict() %>%
235237
layer_threshold(.pred) %>%
236238
layer_naomit(.pred) %>%
237-
layer_population_scaling(.pred, df = reverse_pop_data,
238-
by = NULL,
239-
df_pop_col = "values")
239+
layer_population_scaling(.pred,
240+
df = reverse_pop_data,
241+
by = NULL,
242+
df_pop_col = "values"
243+
)
240244

241-
expect_snapshot(wf <- epi_workflow(r,
242-
parsnip::linear_reg()) %>%
245+
expect_snapshot(wf <- epi_workflow(
246+
r,
247+
parsnip::linear_reg()
248+
) %>%
243249
fit(jhu) %>%
244250
add_frosting(f))
245251

246-
latest <- get_test_data(recipe = r,
247-
x = case_death_rate_subset %>%
248-
dplyr::filter(time_value > "2021-11-01",
249-
geo_value %in% c("ca", "ny")) %>%
250-
dplyr::select(geo_value, time_value, case_rate))
252+
latest <- get_test_data(
253+
recipe = r,
254+
x = case_death_rate_subset %>%
255+
dplyr::filter(
256+
time_value > "2021-11-01",
257+
geo_value %in% c("ca", "ny")
258+
) %>%
259+
dplyr::select(geo_value, time_value, case_rate)
260+
)
251261

252262

253263
expect_snapshot(p <- predict(wf, latest))

0 commit comments

Comments
 (0)