Skip to content

wip lint: maybe bug fix #403

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

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -5,5 +5,6 @@ linters: linters_with_defaults(
)
exclusions: list(
"renv",
"venv"
"venv",
"instr/templates/"
)
29 changes: 18 additions & 11 deletions R/arx_classifier.R
Original file line number Diff line number Diff line change
@@ -58,13 +58,16 @@ arx_classifier <- function(
if (args_list$adjust_latency == "none") {
forecast_date_default <- max(epi_data$time_value)
if (!is.null(args_list$forecast_date) && args_list$forecast_date != forecast_date_default) {
cli_warn("The specified forecast date {args_list$forecast_date} doesn't match the date from which the forecast is occurring {forecast_date}.")
cli_warn(
"The specified forecast date {args_list$forecast_date} doesn't match the date from which the forecast
is occurring {forecast_date}."
)
}
} else {
forecast_date_default <- attributes(epi_data)$metadata$as_of
}
forecast_date <- args_list$forecast_date %||% forecast_date_default
target_date <- args_list$target_date %||% (forecast_date + args_list$ahead)
args_list$forecast_date <- args_list$forecast_date %||% forecast_date_default
args_list$target_date <- args_list$target_date %||% (args_list$forecast_date + args_list$ahead)
preds <- forecast(
wf,
) %>%
@@ -136,7 +139,10 @@ arx_class_epi_workflow <- function(
if (args_list$adjust_latency == "none") {
forecast_date_default <- max(epi_data$time_value)
if (!is.null(args_list$forecast_date) && args_list$forecast_date != forecast_date_default) {
cli_warn("The specified forecast date {args_list$forecast_date} doesn't match the date from which the forecast is occurring {forecast_date}.")
cli_warn(
"The specified forecast date {args_list$forecast_date} doesn't match the date from which the
forecast is occurring {forecast_date}."
)
}
} else {
forecast_date_default <- attributes(epi_data)$metadata$as_of
@@ -209,7 +215,7 @@ arx_class_epi_workflow <- function(
r <- r %>%
step_mutate(
across(
matches(ahead_out_name_regex),
tidyselect::matches(ahead_out_name_regex),
~ cut(.x, breaks = args_list$breaks),
.names = "outcome_class",
.unpack = TRUE
@@ -243,15 +249,16 @@ arx_class_epi_workflow <- function(
#' Constructs a list of arguments for [arx_classifier()].
#'
#' @inheritParams arx_args_list
#' @param outcome_transform Scalar character. Whether the outcome should
#' be created using growth rates (as the predictors are) or lagged
#' differences. The second case is closer to the requirements for the
#' [2022-23 CDC Flusight Hospitalization Experimental Target](https://github.com/cdcepi/Flusight-forecast-data/blob/745511c436923e1dc201dea0f4181f21a8217b52/data-experimental/README.md).
#' @param outcome_transform Scalar character. Whether the outcome should be
#' created using growth rates (as the predictors are) or lagged differences.
#' The second case is closer to the requirements for the [2022-23 CDC Flusight
#' Hospitalization Experimental
#' Target](https://github.com/cdcepi/Flusight-forecast-data/blob/745511c436923e1dc201dea0f4181f21a8217b52/data-experimental/README.md). # nolint: line_length_linter
#' See the Classification Vignette for details of how to create a reasonable
#' baseline for this case. Selecting `"growth_rate"` (the default) uses
#' [epiprocess::growth_rate()] to create the outcome using some of the
#' additional arguments below. Choosing `"lag_difference"` instead simply
#' uses the change from the value at the selected `horizon`.
#' additional arguments below. Choosing `"lag_difference"` instead simply uses
#' the change from the value at the selected `horizon`.
#' @param breaks Vector. A vector of breaks to turn real-valued growth rates
#' into discrete classes. The default gives binary upswing classification
#' as in [McDonald, Bien, Green, Hu, et al.](https://doi.org/10.1073/pnas.2111453118).
10 changes: 7 additions & 3 deletions R/arx_forecaster.R
Original file line number Diff line number Diff line change
@@ -130,7 +130,8 @@ arx_fcast_epi_workflow <- function(
forecast_date_default <- max(epi_data$time_value)
if (!is.null(args_list$forecast_date) && args_list$forecast_date != forecast_date_default) {
cli_warn(
"The specified forecast date {args_list$forecast_date} doesn't match the date from which the forecast is actually occurring {forecast_date_default}.",
"The specified forecast date {args_list$forecast_date} doesn't match the date from which the forecast
is actually occurring {forecast_date_default}.",
class = "epipredict__arx_forecaster__forecast_date_defaulting"
)
}
@@ -140,7 +141,8 @@ arx_fcast_epi_workflow <- function(
forecast_date <- args_list$forecast_date %||% forecast_date_default
target_date <- args_list$target_date %||% (forecast_date + args_list$ahead)
if (forecast_date + args_list$ahead != target_date) {
cli_abort("`forecast_date` {.val {forecast_date}} + `ahead` {.val {ahead}} must equal `target_date` {.val {target_date}}.",
cli_abort(
"`forecast_date` {.val {forecast_date}} + `ahead` {.val {ahead}} must equal `target_date`{.val {target_date}}.",
class = "epipredict__arx_forecaster__inconsistent_target_ahead_forecaste_date"
)
}
@@ -310,7 +312,9 @@ arx_args_list <- function(

if (!is.null(forecast_date) && !is.null(target_date)) {
if (forecast_date + ahead != target_date) {
cli_abort("`forecast_date` {.val {forecast_date}} + `ahead` {.val {ahead}} must equal `target_date` {.val {target_date}}.",
cli_abort(
"`forecast_date` {.val {forecast_date}} + `ahead` {.val {ahead}} must equal `target_date`
{.val {target_date}}.",
class = "epipredict__arx_args__inconsistent_target_ahead_forecaste_date"
)
}
13 changes: 0 additions & 13 deletions R/blueprint-epi_recipe-default.R
Original file line number Diff line number Diff line change
@@ -79,7 +79,6 @@ new_default_epi_recipe_blueprint <-
#' @export
run_mold.default_epi_recipe_blueprint <- function(blueprint, ..., data) {
rlang::check_dots_empty0(...)
# blueprint <- hardhat:::patch_recipe_default_blueprint(blueprint)
cleaned <- mold_epi_recipe_default_clean(blueprint = blueprint, data = data)
blueprint <- cleaned$blueprint
data <- cleaned$data
@@ -97,15 +96,3 @@ mold_epi_recipe_default_clean <- function(blueprint, data) {
refresh_blueprint.default_epi_recipe_blueprint <- function(blueprint) {
do.call(new_default_epi_recipe_blueprint, as.list(blueprint))
}


## removing this function?
# er_check_is_data_like <- function(.x, .x_nm) {
# if (rlang::is_missing(.x_nm)) {
# .x_nm <- rlang::as_label(rlang::enexpr(.x))
# }
# if (!hardhat:::is_new_data_like(.x)) {
# hardhat:::glubort("`{.x_nm}` must be a data.frame or a matrix, not a {class1(.x)}.")
# }
# .x
# }
5 changes: 5 additions & 0 deletions R/epipredict-package.R
Original file line number Diff line number Diff line change
@@ -15,3 +15,8 @@
na_chr <- NA_character_
## usethis namespace: end
NULL
utils::globalVariables(c(
".x", ".group_key", ".ref_time_value", "resid",
"fitted", ".response", "geo_value", "time_value",
"value", ".data", ".env"
))
12 changes: 6 additions & 6 deletions R/utils-arg.R
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ arg_is_pos <- function(..., allow_null = FALSE, call = caller_env()) {
null.ok = allow_null, any.missing = FALSE
)
if (!ok) {
len <- length(value)
len <- length(value) # nolint: object_usage_linter
cli_abort(
"{.arg {name}} must be {cli::qty(len)} {?a/} strictly positive number{?s}.",
call = call
@@ -79,7 +79,7 @@ arg_is_nonneg <- function(..., allow_null = FALSE, call = caller_env()) {
handle_arg_list(..., .tests = function(name, value) {
ok <- test_numeric(value, lower = 0, null.ok = allow_null, any.missing = FALSE)
if (!ok) {
len <- length(value)
len <- length(value) # nolint: object_usage_linter
cli_abort(
"{.arg {name}} must be {cli::qty(len)} {?a/} non-negative number{?s}.",
call = call
@@ -92,7 +92,7 @@ arg_is_int <- function(..., allow_null = FALSE, call = caller_env()) {
handle_arg_list(..., .tests = function(name, value) {
ok <- test_integerish(value, null.ok = allow_null)
if (!ok) {
len <- length(value)
len <- length(value) # nolint: object_usage_linter
cli_abort(
"{.arg {name}} must be {cli::qty(len)} {?a/} integer{?s}.",
call = call
@@ -105,7 +105,7 @@ arg_is_pos_int <- function(..., allow_null = FALSE, call = caller_env()) {
handle_arg_list(..., .tests = function(name, value) {
ok <- test_integerish(value, null.ok = allow_null, lower = 1, any.missing = FALSE)
if (!ok) {
len <- length(value)
len <- length(value) # nolint: object_usage_linter
cli_abort(
"{.arg {name}} must be {cli::qty(len)} {?a/} positive integer{?s}.",
call = call
@@ -118,7 +118,7 @@ arg_is_nonneg_int <- function(..., allow_null = FALSE, call = caller_env()) {
handle_arg_list(..., .tests = function(name, value) {
ok <- test_integerish(value, null.ok = allow_null, lower = 0, any.missing = FALSE)
if (!ok) {
len <- length(value)
len <- length(value) # nolint: object_usage_linter
cli_abort(
"{.arg {name}} must be {cli::qty(len)} {?a/} non-negative integer{?s}.",
call = call
@@ -131,7 +131,7 @@ arg_is_date <- function(..., allow_null = FALSE, call = caller_env()) {
handle_arg_list(..., .tests = function(name, value) {
ok <- test_date(value, null.ok = allow_null)
if (!ok) {
len <- length(value)
len <- length(value) # nolint: object_usage_linter
cli_abort(
"{.arg {name}} must be {cli::qty(len)} {?a/} date{?s}.",
call = call
11 changes: 5 additions & 6 deletions man/arx_class_args_list.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/step_adjust_latency.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.