Skip to content

Commit f399bb9

Browse files
committed
style: consistent use of %<>% over x <- x %>%
1 parent 0e45e78 commit f399bb9

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

R/forecaster_scaled_pop.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ scaled_pop <- function(epi_data,
8484
# preprocessing supported by epipredict
8585
preproc <- epi_recipe(epi_data)
8686
if (pop_scaling) {
87-
preproc <- preproc %>% step_population_scaling(
87+
preproc %<>% step_population_scaling(
8888
all_numeric(),
8989
df = epipredict::state_census,
9090
df_pop_col = "pop",
@@ -93,14 +93,14 @@ scaled_pop <- function(epi_data,
9393
by = c("geo_value" = "abbr")
9494
)
9595
}
96-
preproc <- preproc %>% arx_preprocess(outcome, predictors, args_list)
96+
preproc %<>% arx_preprocess(outcome, predictors, args_list)
9797

9898
# postprocessing supported by epipredict
9999
postproc <- frosting()
100-
postproc <- postproc %>% arx_postprocess(trainer, args_list)
100+
postproc %<>% arx_postprocess(trainer, args_list)
101101
postproc
102102
if (pop_scaling) {
103-
postproc <- postproc %>% layer_population_scaling(
103+
postproc %<>% layer_population_scaling(
104104
.pred, .pred_distn,
105105
df = epipredict::state_census,
106106
df_pop_col = "pop",

R/formatters.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ format_storage <- function(pred, true_forecast_date, target_end_date) {
3737
#' @param quantile_levels the quantile levels
3838
#' @importFrom dplyr group_by rename reframe mutate
3939
format_covidhub <- function(pred, true_forecast_date, target_end_date, quantile_levels) {
40-
pred <- pred %>%
40+
pred %<>%
4141
group_by(forecast_date, geo_value, target_date) %>%
4242
rename(target_end_date = target_date) %>%
4343
reframe(quantile = quantile_levels, value = quantile(.pred_distn, quantile_levels)[[1]])
4444
forecasts$ahead <- ahead
45-
forecasts <- forecasts %>%
45+
forecasts %<>%
4646
group_by(forecast_date, geo_value, target_date) %>%
4747
mutate(forecast_date = target_date - ahead) %>%
4848
rename(target_end_date = target_date) %>%

R/scoring_functions.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ evaluate_predictions <- function(
8888
as_of = Sys.Date()
8989
)
9090
score_card <- collapse_cards(score_card)
91-
score_card <- score_card %>%
91+
score_card %<>%
9292
select(-.data$quantile, -.data$value)
9393

94-
score_card <- score_card %>%
94+
score_card %<>%
9595
relocate(attr(err_measures, "names"), .after = last_col())
9696
return(score_card)
9797
}
@@ -117,14 +117,14 @@ collapse_cards <- function(cards) {
117117
"predictions_cards or score_cards classes."
118118
)
119119
)
120-
cards <- cards %>%
120+
cards %<>%
121121
filter(abs(.data$quantile - 0.5) < 1e-8 | is.na(.data$quantile)) %>%
122122
mutate(quantile = ifelse(is.na(.data$quantile), "p", "m"))
123123
if (n_distinct(cards$quantile) == 1) {
124-
cards <- cards %>%
124+
cards %<>%
125125
mutate(quantile = ifelse(.data$quantile == "p", NA, 0.5))
126126
} else {
127-
cards <- cards %>%
127+
cards %<>%
128128
pivot_wider(names_from = .data$quantile, values_from = .data$value) %>%
129129
mutate(
130130
quantile = ifelse(is.na(.data$p), 0.5, NA),
@@ -133,7 +133,7 @@ collapse_cards <- function(cards) {
133133
select(-.data$p, -.data$m)
134134
}
135135
if ("geo_value" %in% colnames(cards)) {
136-
cards <- cards %>%
136+
cards %<>%
137137
relocate(.data$quantile:.data$value, .after = .data$geo_value)
138138
}
139139
class(cards) <- c(cls, class(cards))

R/small_utils.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ add_id <- function(df, n_adj = 2) {
2828
mutate(id = paste(across(everything()), sep = "", collapse = ""), .keep = "none") %>%
2929
mutate(id = hash_animal(id, n_adj = n_adj)$words) %>%
3030
mutate(id = paste(id[1:n_adj], sep = "", collapse = "."))
31-
df <- df %>%
31+
df %<>%
3232
ungroup() %>%
3333
mutate(parent_id = stringified$id) %>%
3434
rowwise() %>%
@@ -81,7 +81,7 @@ id_ahead_ensemble_grid <- function(ensemble_grid, aheads, n_adj = 2) {
8181
tibble(ahead = aheads)
8282
)
8383

84-
ensemble_grid <- ensemble_grid %>%
84+
ensemble_grid %<>%
8585
add_id(., n_adj = 2) %>%
8686
rowwise() %>%
8787
mutate(forecaster_ids = list(map2_vec(forecasters, ahead, single_id, n_adj = 2)))

extras/plotting.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ get_points_df <- function(predictions_cards) {
4747
is.na(.data$quantile)
4848
)
4949
if (any(is.na(points_df$quantile))) {
50-
points_df <- points_df %>%
50+
points_df %<>%
5151
pivot_wider(names_from = "quantile", values_from = "value") %>%
5252
mutate(value = if_else(!is.na(.data$`NA`), .data$`NA`, .data$`0.5`)) %>%
5353
select(-.data$`0.5`, -.data$`NA`)
5454
} else {
55-
points_df <- points_df %>%
55+
points_df %<>%
5656
select(-.data$quantile)
5757
}
5858

@@ -102,7 +102,7 @@ plot_state_forecasters <- function(
102102
return(NULL)
103103
}
104104

105-
predictions_cards <- predictions_cards %>%
105+
predictions_cards %<>%
106106
filter(!geo_value %in% exclude_geos)
107107

108108
td1 <- tar_read("hhs_latest_data_2022") %>%
@@ -123,11 +123,11 @@ plot_state_forecasters <- function(
123123
td2_max <- td2_max %>%
124124
left_join(td1_max, by = "geo_value", suffix = c(".2", ".1")) %>%
125125
mutate(max_ratio = max_value.1 / max_value.2)
126-
td2 <- td2 %>%
126+
td2 %<>%
127127
left_join(td2_max, by = "geo_value") %>%
128128
mutate(scaled_value = value * max_ratio)
129-
td1 <- td1 %>% mutate(forecaster = "hhs hosp truth")
130-
td2 <- td2 %>% mutate(forecaster = "chng smoothed_adj_outpatient_flu current, scaled")
129+
td1 %<>% mutate(forecaster = "hhs hosp truth")
130+
td2 %<>% mutate(forecaster = "chng smoothed_adj_outpatient_flu current, scaled")
131131

132132
# Setup plot
133133
g <- ggplot(td1, mapping = aes(
@@ -164,7 +164,7 @@ plot_nation_forecasters <- function(
164164
return(NULL)
165165
}
166166

167-
predictions_cards <- predictions_cards %>%
167+
predictions_cards %<>%
168168
filter(!geo_value %in% exclude_geos) %>%
169169
group_by(forecaster, forecast_date, quantile, target_end_date) %>%
170170
summarize(value = sum(value)) %>%
@@ -194,7 +194,7 @@ plot_nation_forecasters <- function(
194194
td2.max <- td2 %>%
195195
summarize(max_value = max(value)) %>%
196196
pull(max_value)
197-
td2 <- td2 %>%
197+
td2 %<>%
198198
mutate(scaled_value = value * td1.max / td2.max)
199199

200200
# Setup plot

0 commit comments

Comments
 (0)