Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make tidyverse syntax compliant with tidyverse guidelines for packages #8

Closed
wants to merge 9 commits into from
6 changes: 6 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
^renv$
^renv\.lock$
^LICENSE\.md$
^DISCLAIMER\.md$
^CONTRIBUTING\.md$
^open_practices\.md$
^rules_of_behavior\.md$
^code-of-conduct\.md$
^thanks\.md$
^_pkgdown\.yml$
^docs$
^pkgdown$
Expand Down
201 changes: 0 additions & 201 deletions LICENSE

This file was deleted.

1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export(update_hub)
export(us_loc_abbr_to_code)
export(us_loc_code_to_abbr)
export(validate_base_forecasts)
importFrom(rlang,":=")
importFrom(rlang,.data)
42 changes: 22 additions & 20 deletions R/create_table_for_scoring.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ update_hub <- function(hub_path) {
gather_hub_forecast_data <- function(hub_path) {
hub_connection <- hubData::connect_hub(hub_path)
forecasts <- hub_connection |>
dplyr::filter(output_type == "quantile") |>
dplyr::filter(horizon >= 0) |>
dplyr::rename(prediction = value) |>
dplyr::rename(forecast_date = reference_date) |>
dplyr::rename(quantile = output_type_id) |>
dplyr::filter(.data$output_type == "quantile") |>
dplyr::filter(.data$horizon >= 0) |>
dplyr::rename(
"prediction" = "value",
"forecast_date" = "reference_date",
"quantile" = "output_type_id"
) |>
dplyr::collect()
return(forecasts)
}
Expand Down Expand Up @@ -115,7 +117,7 @@ gather_target_data <- function(hub_path,
if (truth_data_path |> fs::file_exists()) {
target_data <-
readr::read_csv(truth_data_path) |>
dplyr::rename(true_value = value)
dplyr::rename("true_value" = "value")
return(target_data)
} else {
cfl <- truth_data_path
Expand Down Expand Up @@ -146,23 +148,23 @@ create_table_for_scoring <- function(hub_path) {
forecasts_only,
target_data,
by = dplyr::join_by(
location == location,
target_end_date == date
"location" == "location",
"target_end_date" == "date"
)
) |>
dplyr::rename(model = model_id) |>
dplyr::mutate(target_end_date = as.Date(target_end_date)) |>
dplyr::mutate(quantile = as.numeric(quantile)) |>
dplyr::rename("model" = "model_id") |>
dplyr::mutate("target_end_date" = as.Date(.data$target_end_date)) |>
dplyr::mutate("quantile" = as.numeric(.data$quantile)) |>
dplyr::select(
forecast_date,
target_end_date,
horizon,
location,
quantile,
prediction,
location_name,
true_value,
model
"forecast_date",
"target_end_date",
"horizon",
"location",
"quantile",
"prediction",
"location_name",
"true_value",
"model"
)

return(forecasts_and_targets)
Expand Down
10 changes: 5 additions & 5 deletions R/daily_to_epiweekly.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ daily_to_epiweekly <- function(tidy_daily_trajectories,

grouped_df <- tidy_daily_trajectories |>
dplyr::mutate(
epiweek = lubridate::epiweek(.data[[!!date_col]]),
epiyear = lubridate::epiyear(.data[[!!date_col]])
"epiweek" = lubridate::epiweek(.data[[!!date_col]]),
"epiyear" = lubridate::epiyear(.data[[!!date_col]])
) |>
dplyr::group_by(
epiweek,
epiyear,
.data$epiweek,
.data$epiyear,
dplyr::across(tidyselect::all_of(!!id_cols))
)

n_elements <- grouped_df |>
dplyr::summarise(n_elements = dplyr::n()) |>
dplyr::summarise("n_elements" = dplyr::n()) |>
dplyr::pull()

## check that no weeks have more than
Expand Down
12 changes: 6 additions & 6 deletions R/filter_for_scoring.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ filter_for_scoring <- function(forecasts_and_targets,
"Filtering out forecasts without corresponding truth data..."
)
to_score <- to_score |>
dplyr::filter(!is.na(true_value))
dplyr::filter(!is.na(.data$true_value))
}

# filter forecasts to score
Expand All @@ -48,21 +48,21 @@ filter_for_scoring <- function(forecasts_and_targets,
"Filtering out forecast dates before {min_forecast_date}"
)
to_score <- to_score |>
dplyr::filter(forecast_date >= as.Date(!!min_forecast_date))
dplyr::filter(.data$forecast_date >= as.Date(!!min_forecast_date))
}
if (!is.null(max_forecast_date)) {
cli::cli_inform(
"Filtering out forecast dates after {max_forecast_date}"
)
to_score <- to_score |>
dplyr::filter(forecast_date <= as.Date(!!max_forecast_date))
dplyr::filter(.data$forecast_date <= as.Date(!!max_forecast_date))
}
if (!is.null(horizons)) {
cli::cli_inform(
"Filtering out horizons not in {horizons}"
)
to_score <- to_score |>
dplyr::filter(horizon %in% c(!!horizons))
dplyr::filter(.data$horizon %in% c(!!horizons))
}
if (!is.null(locations)) {
cli::cli_inform(
Expand All @@ -73,14 +73,14 @@ filter_for_scoring <- function(forecasts_and_targets,
locations
)
to_score <- to_score |>
dplyr::filter(location %in% c(!!loc_codes))
dplyr::filter(.data$location %in% c(!!loc_codes))
}
if (!is.null(models)) {
cli::cli_inform(
"Filtering out models not in {models}"
)
to_score <- to_score |>
dplyr::filter(model %in% c(!!models))
dplyr::filter(.data$model %in% c(!!models))
}

return(to_score)
Expand Down
1 change: 1 addition & 0 deletions R/forecasttools-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"_PACKAGE"

## usethis namespace: start
#' @importFrom rlang :=
#' @importFrom rlang .data
## usethis namespace: end
NULL
6 changes: 3 additions & 3 deletions R/simple_bottom_up.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ count_trajectories <- function(base_forecasts,
location_col,
date_col) {
number_of_sampled_trajs <- base_forecasts |>
dplyr::group_by(.data[[location_col]], .data[[date_col]]) |>
dplyr::summarise(n_sample_trajs = dplyr::n()) |>
dplyr::group_by(.data[[!!location_col]], .data[[!!date_col]]) |>
dplyr::summarise("n_sample_trajs" = dplyr::n()) |>
dplyr::ungroup() |>
dplyr::select(dplyr::all_of(location_col), n_sample_trajs) |>
dplyr::select(dplyr::all_of(!!location_col), "n_sample_trajs") |>
dplyr::distinct()
return(number_of_sampled_trajs)
}
Expand Down
Loading