Skip to content

Commit f7d7612

Browse files
committed
run styler
1 parent 0f5537e commit f7d7612

9 files changed

+75
-69
lines changed

R/cdc_baseline_forecaster.R

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@
3737
#' preds <- pivot_quantiles_wider(cdc$predictions, .pred_distn)
3838
#'
3939
#' if (require(ggplot2)) {
40-
#' forecast_date <- unique(preds$forecast_date)
41-
#' four_states <- c("ca", "pa", "wa", "ny")
42-
#' preds %>%
43-
#' filter(geo_value %in% four_states) %>%
44-
#' ggplot(aes(target_date)) +
45-
#' geom_ribbon(aes(ymin = `0.1`, ymax = `0.9`), fill = blues9[3]) +
46-
#' geom_ribbon(aes(ymin = `0.25`, ymax = `0.75`), fill = blues9[6]) +
47-
#' geom_line(aes(y = .pred), color = "orange") +
48-
#' geom_line(
49-
#' data = weekly_deaths %>% filter(geo_value %in% four_states),
50-
#' aes(x = time_value, y = deaths)
51-
#' ) +
52-
#' scale_x_date(limits = c(forecast_date - 90, forecast_date + 30)) +
53-
#' labs(x = "Date", y = "Weekly deaths") +
54-
#' facet_wrap(~geo_value, scales = "free_y") +
55-
#' theme_bw() +
56-
#' geom_vline(xintercept = forecast_date)
40+
#' forecast_date <- unique(preds$forecast_date)
41+
#' four_states <- c("ca", "pa", "wa", "ny")
42+
#' preds %>%
43+
#' filter(geo_value %in% four_states) %>%
44+
#' ggplot(aes(target_date)) +
45+
#' geom_ribbon(aes(ymin = `0.1`, ymax = `0.9`), fill = blues9[3]) +
46+
#' geom_ribbon(aes(ymin = `0.25`, ymax = `0.75`), fill = blues9[6]) +
47+
#' geom_line(aes(y = .pred), color = "orange") +
48+
#' geom_line(
49+
#' data = weekly_deaths %>% filter(geo_value %in% four_states),
50+
#' aes(x = time_value, y = deaths)
51+
#' ) +
52+
#' scale_x_date(limits = c(forecast_date - 90, forecast_date + 30)) +
53+
#' labs(x = "Date", y = "Weekly deaths") +
54+
#' facet_wrap(~geo_value, scales = "free_y") +
55+
#' theme_bw() +
56+
#' geom_vline(xintercept = forecast_date)
5757
#' }
5858
cdc_baseline_forecaster <- function(
5959
epi_data,
@@ -95,7 +95,7 @@ cdc_baseline_forecaster <- function(
9595
) %>%
9696
layer_add_forecast_date(forecast_date = forecast_date) %>%
9797
layer_unnest(.pred_distn_all)
98-
# layer_add_target_date(target_date = target_date)
98+
# layer_add_target_date(target_date = target_date)
9999
if (args_list$nonneg) f <- layer_threshold(f, ".pred")
100100

101101
eng <- parsnip::linear_reg() %>% parsnip::set_engine("flatline")
@@ -213,8 +213,7 @@ parse_period <- function(x) {
213213
if (length(x) == 1L) x <- as.numeric(x)
214214
if (length(x) == 2L) {
215215
mult <- substr(x[2], 1, 3)
216-
mult <- switch(
217-
mult,
216+
mult <- switch(mult,
218217
day = 1L,
219218
wee = 7L,
220219
cli::cli_abort("incompatible timespan in `aheads`.")

R/epi_recipe.R

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,11 @@ print.epi_recipe <- function(x, form_width = 30, ...) {
456456
cli::cli_h3("Operations")
457457
}
458458

459-
i = 1
459+
i <- 1
460460
for (step in x$steps) {
461461
cat(paste0(i, ". "))
462462
print(step, form_width = form_width)
463-
i = i + 1
463+
i <- i + 1
464464
}
465465
cli::cli_end()
466466

@@ -469,20 +469,20 @@ print.epi_recipe <- function(x, form_width = 30, ...) {
469469

470470
# Currently only used in the workflow printing
471471
print_preprocessor_recipe <- function(x, ...) {
472-
473472
recipe <- workflows::extract_preprocessor(x)
474473
steps <- recipe$steps
475474
n_steps <- length(steps)
476475
if (n_steps == 1L) {
477476
step <- "Step"
478-
}
479-
else {
477+
} else {
480478
step <- "Steps"
481479
}
482480
n_steps_msg <- glue::glue("{n_steps} Recipe {step}")
483481
cat_line(n_steps_msg)
484482

485-
if (n_steps == 0L) return(invisible(x))
483+
if (n_steps == 0L) {
484+
return(invisible(x))
485+
}
486486

487487
cat_line("")
488488

@@ -498,8 +498,7 @@ print_preprocessor_recipe <- function(x, ...) {
498498

499499
if (extra_steps == 1L) {
500500
step <- "step"
501-
}
502-
else {
501+
} else {
503502
step <- "steps"
504503
}
505504

@@ -512,7 +511,6 @@ print_preprocessor_recipe <- function(x, ...) {
512511
}
513512

514513
print_preprocessor <- function(x) {
515-
516514
has_preprocessor_formula <- workflows:::has_preprocessor_formula(x)
517515
has_preprocessor_recipe <- workflows:::has_preprocessor_recipe(x)
518516
has_preprocessor_variables <- workflows:::has_preprocessor_variables(x)
@@ -532,7 +530,7 @@ print_preprocessor <- function(x) {
532530
workflows:::print_preprocessor_formula(x)
533531
}
534532
if (has_preprocessor_recipe) {
535-
print_preprocessor_recipe(x)
533+
print_preprocessor_recipe(x)
536534
}
537535
if (has_preprocessor_variables) {
538536
workflows:::print_preprocessor_variables(x)

R/epi_workflow.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ new_epi_workflow <- function(
219219
print.epi_workflow <- function(x, ...) {
220220
print_header(x)
221221
print_preprocessor(x)
222-
#workflows:::print_case_weights(x)
222+
# workflows:::print_case_weights(x)
223223
workflows:::print_model(x)
224224
print_postprocessor(x)
225225
invisible(x)

R/flusight_hub_formatter.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
abbr_to_fips <- function(abbr) {
22
fi <- dplyr::left_join(
33
tibble::tibble(abbr = tolower(abbr)),
4-
state_census, by = "abbr") %>%
4+
state_census,
5+
by = "abbr"
6+
) %>%
57
dplyr::mutate(fips = as.character(fips), fips = case_when(
68
fips == "0" ~ "US",
79
nchar(fips) < 2L ~ paste0("0", fips),
@@ -118,14 +120,15 @@ flusight_hub_formatter.data.frame <- function(
118120
} else if (!is.na(has_ahead)) { # ahead present, not target date
119121
object <- object %>%
120122
dplyr::rename(horizon = !!names(object)[has_ahead]) %>%
121-
dplyr::mutate(target_end_date = horizon * pp + reference_date)
123+
dplyr::mutate(target_end_date = horizon * pp + reference_date)
122124
} else { # target_date present, not ahead
123125
object <- object %>%
124126
dplyr::rename(target_end_date = target_date) %>%
125127
dplyr::mutate(horizon = as.integer((target_end_date - reference_date)) / pp)
126128
}
127-
object %>% dplyr::relocate(
128-
reference_date, horizon, target_end_date, location, output_type_id, value
129-
) %>%
129+
object %>%
130+
dplyr::relocate(
131+
reference_date, horizon, target_end_date, location, output_type_id, value
132+
) %>%
130133
dplyr::mutate(!!!dots)
131134
}

R/frosting.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,11 @@ print.frosting <- function(x, form_width = 30, ...) {
294294
cli::cli_h1("Frosting")
295295

296296
if (!is.null(x$layers)) cli::cli_h3("Layers")
297-
i = 1
298-
for (layer in x$layers){
297+
i <- 1
298+
for (layer in x$layers) {
299299
cat(paste0(i, ". "))
300300
print(layer, form_width = form_width)
301-
i = i + 1
301+
i <- i + 1
302302
}
303303
cli::cli_end()
304304
invisible(x)

R/layer_cdc_flatline_quantiles.R

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,22 @@
8686
#' mutate(target_date = forecast_date + ahead)
8787
#'
8888
#' if (require("ggplot2")) {
89-
#' four_states <- c("ca", "pa", "wa", "ny")
90-
#' preds %>%
91-
#' filter(geo_value %in% four_states) %>%
92-
#' ggplot(aes(target_date)) +
93-
#' geom_ribbon(aes(ymin = `0.1`, ymax = `0.9`), fill = blues9[3]) +
94-
#' geom_ribbon(aes(ymin = `0.25`, ymax = `0.75`), fill = blues9[6]) +
95-
#' geom_line(aes(y = .pred), color = "orange") +
96-
#' geom_line(
97-
#' data = case_death_rate_subset %>% filter(geo_value %in% four_states),
98-
#' aes(x = time_value, y = death_rate)
99-
#' ) +
100-
#' scale_x_date(limits = c(forecast_date - 90, forecast_date + 30)) +
101-
#' labs(x = "Date", y = "Death rate") +
102-
#' facet_wrap(~geo_value, scales = "free_y") +
103-
#' theme_bw() +
104-
#' geom_vline(xintercept = forecast_date)
89+
#' four_states <- c("ca", "pa", "wa", "ny")
90+
#' preds %>%
91+
#' filter(geo_value %in% four_states) %>%
92+
#' ggplot(aes(target_date)) +
93+
#' geom_ribbon(aes(ymin = `0.1`, ymax = `0.9`), fill = blues9[3]) +
94+
#' geom_ribbon(aes(ymin = `0.25`, ymax = `0.75`), fill = blues9[6]) +
95+
#' geom_line(aes(y = .pred), color = "orange") +
96+
#' geom_line(
97+
#' data = case_death_rate_subset %>% filter(geo_value %in% four_states),
98+
#' aes(x = time_value, y = death_rate)
99+
#' ) +
100+
#' scale_x_date(limits = c(forecast_date - 90, forecast_date + 30)) +
101+
#' labs(x = "Date", y = "Death rate") +
102+
#' facet_wrap(~geo_value, scales = "free_y") +
103+
#' theme_bw() +
104+
#' geom_vline(xintercept = forecast_date)
105105
#' }
106106
layer_cdc_flatline_quantiles <- function(
107107
frosting,
@@ -160,7 +160,9 @@ layer_cdc_flatline_quantiles_new <- function(
160160
#' @export
161161
slather.layer_cdc_flatline_quantiles <-
162162
function(object, components, workflow, new_data, ...) {
163-
if (is.null(object$quantile_levels)) return(components)
163+
if (is.null(object$quantile_levels)) {
164+
return(components)
165+
}
164166
the_fit <- workflows::extract_fit_parsnip(workflow)
165167
if (!inherits(the_fit, "_flatline")) {
166168
cli::cli_warn(
@@ -245,8 +247,10 @@ propagate_samples <- function(
245247
if (symmetrize) {
246248
r <- c(r, -r)
247249
}
248-
samp <- quantile(r, probs = c(0, seq_len(nsim - 1)) / (nsim - 1),
249-
na.rm = TRUE, names = FALSE)
250+
samp <- quantile(r,
251+
probs = c(0, seq_len(nsim - 1)) / (nsim - 1),
252+
na.rm = TRUE, names = FALSE
253+
)
250254
res <- list()
251255

252256
raw <- samp + p

R/make_smooth_quantile_reg.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@
6363
#' lines(pl$x, pl$`0.5`, col = "red")
6464
#'
6565
#' if (require("ggplot2")) {
66-
#' ggplot(data.frame(x = x, y = y), aes(x)) +
67-
#' geom_ribbon(data = pl, aes(ymin = `0.2`, ymax = `0.8`), fill = "lightblue") +
68-
#' geom_point(aes(y = y), colour = "grey") + # observed data
69-
#' geom_function(fun = sin, colour = "black") + # truth
70-
#' geom_vline(xintercept = fd, linetype = "dashed") + # end of training data
71-
#' geom_line(data = pl, aes(y = `0.5`), colour = "red") + # median prediction
72-
#' theme_bw() +
73-
#' coord_cartesian(xlim = c(0, NA)) +
74-
#' ylab("y")
66+
#' ggplot(data.frame(x = x, y = y), aes(x)) +
67+
#' geom_ribbon(data = pl, aes(ymin = `0.2`, ymax = `0.8`), fill = "lightblue") +
68+
#' geom_point(aes(y = y), colour = "grey") + # observed data
69+
#' geom_function(fun = sin, colour = "black") + # truth
70+
#' geom_vline(xintercept = fd, linetype = "dashed") + # end of training data
71+
#' geom_line(data = pl, aes(y = `0.5`), colour = "red") + # median prediction
72+
#' theme_bw() +
73+
#' coord_cartesian(xlim = c(0, NA)) +
74+
#' ylab("y")
7575
#' }
7676
smooth_quantile_reg <- function(
7777
mode = "regression",

R/print_epi_step.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ print_epi_step <- function(
4444
)
4545
more_dots <- ifelse(first_line == length(elements), "", ", ...")
4646
cli::cli_bullets(
47-
c("\n {title}: \\\n {.pkg {cli::cli_vec(elements[seq_len(first_line)])}}\\\n {more_dots} \\\n {conjunction} \\\n {.pkg {extra_text}} \\\n {vline_seperator} \\\n {.emph {trained_text}}\\\n {comma_seperator} \\\n {.emph {case_weights_text}}\n "))
47+
c("\n {title}: \\\n {.pkg {cli::cli_vec(elements[seq_len(first_line)])}}\\\n {more_dots} \\\n {conjunction} \\\n {.pkg {extra_text}} \\\n {vline_seperator} \\\n {.emph {trained_text}}\\\n {comma_seperator} \\\n {.emph {case_weights_text}}\n ")
48+
)
4849

4950
cli::cli_end(theme_div_id)
5051
invisible(NULL)

R/print_layer.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ print_layer <- function(
2525
)
2626
more_dots <- ifelse(first_line == length(elements), "", ", ...")
2727
cli::cli_bullets(
28-
c("\n {title}: \\\n {.pkg {elements[seq_len(first_line)]}}\\\n {more_dots} \\\n {conjunction} \\\n {.pkg {extra_text}}"))
28+
c("\n {title}: \\\n {.pkg {elements[seq_len(first_line)]}}\\\n {more_dots} \\\n {conjunction} \\\n {.pkg {extra_text}}")
29+
)
2930

3031
invisible(NULL)
3132
}

0 commit comments

Comments
 (0)