Skip to content

Commit 4081f28

Browse files
committed
refactor: minor epieval package
* don't reexport pipe * import %>% and %<>% * bring back %<>% * consolidate dplyr imports in one place * update <name>-package.R name * document
1 parent f399bb9 commit 4081f28

13 files changed

+27
-70
lines changed

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
export("%>%")
43
export(absolute_error)
54
export(add_id)
65
export(arx_postprocess)
@@ -74,6 +73,7 @@ importFrom(epipredict,step_population_scaling)
7473
importFrom(epipredict,step_training_window)
7574
importFrom(epiprocess,epix_slide)
7675
importFrom(here,here)
76+
importFrom(magrittr,"%<>%")
7777
importFrom(magrittr,"%>%")
7878
importFrom(purrr,map)
7979
importFrom(purrr,map2_vec)

R/epieval-package.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#' @importFrom magrittr %>% %<>%
2+
#' @importFrom dplyr select rename inner_join join_by mutate relocate any_of group_by reframe summarize left_join across filter rowwise everything ungroup
3+
#' @importFrom purrr transpose map map2_vec
4+
#' @keywords internal
5+
"_PACKAGE"
6+
.onLoad <- function(libname, pkgname) {
7+
epidatr::set_cache(
8+
cache_dir = ".exploration_cache",
9+
days = 14,
10+
max_size = 4,
11+
confirm = FALSE
12+
)
13+
}

R/exploration-tooling-package.R

Lines changed: 0 additions & 10 deletions
This file was deleted.

R/forecaster.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ arx_preprocess <- function(rec, outcome, predictors, args_list) {
8484
p <- predictors[l]
8585
rec <- rec %>% step_epi_lag(!!p, lag = lags[[l]])
8686
}
87-
rec <- rec %>%
87+
rec %<>%
8888
step_epi_ahead(!!outcome, ahead = args_list$ahead) %>%
8989
step_epi_naomit() %>%
9090
step_training_window(n_recent = args_list$n_training)
@@ -112,22 +112,22 @@ arx_postprocess <- function(postproc,
112112
args_list,
113113
forecast_date = NULL,
114114
target_date = NULL) {
115-
postproc <- postproc %>% layer_predict()
115+
postproc %<>% layer_predict()
116116
if (inherits(trainer, "quantile_reg")) {
117-
postproc <- postproc %>%
117+
postproc %<>%
118118
layer_quantile_distn(quantile_levels = args_list$quantile_levels) %>%
119119
layer_point_from_distn()
120120
} else {
121-
postproc <- postproc %>% layer_residual_quantiles(
121+
postproc %<>% layer_residual_quantiles(
122122
quantile_levels = args_list$quantile_levels, symmetrize = args_list$symmetrize,
123123
by_key = args_list$quantile_by_key
124124
)
125125
}
126126
if (args_list$nonneg) {
127-
postproc <- postproc %>% layer_threshold(dplyr::starts_with(".pred"))
127+
postproc %<>% layer_threshold(dplyr::starts_with(".pred"))
128128
}
129129

130-
postproc <- postproc %>%
130+
postproc %<>%
131131
layer_naomit(dplyr::starts_with(".pred")) %>%
132132
layer_add_target_date(target_date = target_date)
133133
return(postproc)
@@ -177,7 +177,6 @@ run_workflow_and_format <- function(preproc, postproc, trainer, epi_data) {
177177
#' @param forecaster_args_names a bit of a hack around targets, it contains
178178
#' the names of the `forecaster_args`.
179179
#' @importFrom epiprocess epix_slide
180-
#' @importFrom dplyr select rename inner_join join_by
181180
#' @importFrom cli cli_abort
182181
#' @importFrom rlang !!
183182
#' @export
@@ -235,14 +234,14 @@ forecaster_pred <- function(data,
235234
before = before,
236235
ref_time_values = valid_predict_dates,
237236
)
238-
res <- res %>% select(-time_value)
237+
res %<>% select(-time_value)
239238
names(res) <- sub("^slide_value_", "", names(res))
240239

241240
# append the truth data
242241
true_value <- archive$as_of(archive$versions_end) %>%
243242
select(geo_value, time_value, !!outcome) %>%
244243
rename(true_value = !!outcome)
245-
res <- res %>%
244+
res %<>%
246245
inner_join(true_value,
247246
by = join_by(geo_value, target_end_date == time_value)
248247
)

R/formatters.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#' making the forecast, rather than the last day of available data
1010
#' @param target_end_date the date of the prediction
1111
#' @importFrom epipredict nested_quantiles
12-
#' @importFrom dplyr mutate select rename relocate any_of
1312
#' @importFrom tidyr unnest
1413
#' @export
1514
format_storage <- function(pred, true_forecast_date, target_end_date) {
@@ -35,7 +34,6 @@ format_storage <- function(pred, true_forecast_date, target_end_date) {
3534
#' making the forecast, rather than the last day of available data
3635
#' @param target_end_date the date of the prediction
3736
#' @param quantile_levels the quantile levels
38-
#' @importFrom dplyr group_by rename reframe mutate
3937
format_covidhub <- function(pred, true_forecast_date, target_end_date, quantile_levels) {
4038
pred %<>%
4139
group_by(forecast_date, geo_value, target_date) %>%

R/scoring_functions.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#'
4141
#' @importFrom rlang quo .data
4242
#' @importFrom assertthat assert_that
43-
#' @importFrom dplyr group_by summarize inner_join left_join mutate relocate across
4443
#' @export
4544
evaluate_predictions <- function(
4645
predictions_cards,
@@ -106,7 +105,6 @@ evaluate_predictions <- function(
106105
#'
107106
#' @importFrom assertthat assert_that
108107
#' @importFrom tidyr pivot_wider
109-
#' @importFrom dplyr filter mutate relocate select
110108
#'
111109
#' @export
112110
collapse_cards <- function(cards) {

R/small_utils.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ covidhub_probs <- function(type = c("standard", "inc_case")) {
1616
#' and append the `ahead` at the end.
1717
#' @param df the df to add a column to. everything should be convertable to a string
1818
#' @param n_adj the number of adjectives to use; default of 2.
19-
#' @importFrom dplyr select rowwise mutate across everything ungroup
2019
#' @importFrom cli hash_animal
2120
#' @export
2221
add_id <- function(df, n_adj = 2) {
@@ -72,8 +71,6 @@ lookup_ids <- function() {
7271
#' @inheritParams add_id
7372
#' @importFrom tidyr expand_grid
7473
#' @importFrom tibble tibble
75-
#' @importFrom purrr map2_vec
76-
#' @importFrom dplyr rowwise mutate
7774
#' @export
7875
id_ahead_ensemble_grid <- function(ensemble_grid, aheads, n_adj = 2) {
7976
ensemble_grid <- expand_grid(

R/targets_utils.R

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
#' @param param_grid the tibble of parameters. Must have forecaster and trainer, everything else is optional
66
#' @export
77
#' @importFrom rlang syms
8-
#' @importFrom purrr map
9-
#' @importFrom dplyr mutate
108
make_target_param_grid <- function(param_grid) {
11-
param_grid <- param_grid %>% mutate(forecaster = syms(forecaster))
12-
param_grid <- param_grid %>% mutate(trainer = syms(trainer))
9+
param_grid %<>% mutate(forecaster = syms(forecaster))
10+
param_grid %<>% mutate(trainer = syms(trainer))
1311
list_of_params <- lists_of_real_values(param_grid)
1412
list_names <- map(list_of_params, names)
1513
tibble(
@@ -22,8 +20,6 @@ make_target_param_grid <- function(param_grid) {
2220

2321
#' helper function for `make_target_param_grid`
2422
#' @keywords internal
25-
#' @importFrom purrr transpose map
26-
#' @importFrom dplyr select
2723
lists_of_real_values <- function(param_grid) {
2824
full_lists <- transpose(param_grid %>% select(-forecaster, -id))
2925
filter_nonvalues <- function(x) {

R/utils-pipe.R

Lines changed: 0 additions & 14 deletions
This file was deleted.

man/epieval-package.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pipe.Rd

Lines changed: 0 additions & 20 deletions
This file was deleted.

man/read_external_predictions_data.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/run_evaluation_measure.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)