diff --git a/.lintr b/.lintr index c7c90554d..bae1e68b2 100644 --- a/.lintr +++ b/.lintr @@ -5,5 +5,6 @@ linters: linters_with_defaults( ) exclusions: list( "renv", - "venv" + "venv", + "instr/templates/" ) diff --git a/R/arx_classifier.R b/R/arx_classifier.R index 0aec0e362..3b77f97b0 100644 --- a/R/arx_classifier.R +++ b/R/arx_classifier.R @@ -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). diff --git a/R/arx_forecaster.R b/R/arx_forecaster.R index bfd5eaec1..a2a60b5e1 100644 --- a/R/arx_forecaster.R +++ b/R/arx_forecaster.R @@ -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" ) } diff --git a/R/blueprint-epi_recipe-default.R b/R/blueprint-epi_recipe-default.R index 886cd5512..7c59ca003 100644 --- a/R/blueprint-epi_recipe-default.R +++ b/R/blueprint-epi_recipe-default.R @@ -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 -# } diff --git a/R/epipredict-package.R b/R/epipredict-package.R index ad0f95295..f4e76ca40 100644 --- a/R/epipredict-package.R +++ b/R/epipredict-package.R @@ -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" +)) diff --git a/R/utils-arg.R b/R/utils-arg.R index 081d153fb..c750bd3ca 100644 --- a/R/utils-arg.R +++ b/R/utils-arg.R @@ -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 diff --git a/man/arx_class_args_list.Rd b/man/arx_class_args_list.Rd index a229b67c0..1b79e3aee 100644 --- a/man/arx_class_args_list.Rd +++ b/man/arx_class_args_list.Rd @@ -64,15 +64,14 @@ data was 3 days ago, the lags become \code{c(3,10,17)}. \item{warn_latency}{by default, \code{step_adjust_latency} warns the user if the latency is large. If this is \code{FALSE}, that warning is turned off.} -\item{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 -\href{https://github.com/cdcepi/Flusight-forecast-data/blob/745511c436923e1dc201dea0f4181f21a8217b52/data-experimental/README.md}{2022-23 CDC Flusight Hospitalization Experimental Target}. +\item{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 \href{https://github.com/cdcepi/Flusight-forecast-data/blob/745511c436923e1dc201dea0f4181f21a8217b52/data-experimental/README.md}{2022-23 CDC Flusight Hospitalization Experimental Target}. # nolint: line_length_linter See the Classification Vignette for details of how to create a reasonable baseline for this case. Selecting \code{"growth_rate"} (the default) uses \code{\link[epiprocess:growth_rate]{epiprocess::growth_rate()}} to create the outcome using some of the -additional arguments below. Choosing \code{"lag_difference"} instead simply -uses the change from the value at the selected \code{horizon}.} +additional arguments below. Choosing \code{"lag_difference"} instead simply uses +the change from the value at the selected \code{horizon}.} \item{breaks}{Vector. A vector of breaks to turn real-valued growth rates into discrete classes. The default gives binary upswing classification diff --git a/man/step_adjust_latency.Rd b/man/step_adjust_latency.Rd index f0ee41390..e1e516a3c 100644 --- a/man/step_adjust_latency.Rd +++ b/man/step_adjust_latency.Rd @@ -260,8 +260,8 @@ while this will not: \if{html}{\out{
}}\preformatted{toy_recipe <- epi_recipe(toy_df) \%>\% step_epi_lag(a, lag=0) \%>\% step_adjust_latency(a, method = "extend_lags") -#> Warning: If `method` is "extend_lags" or "locf", then the previous `step_epi_lag`s won't work with -#> modified data. +#> Warning: If `method` is "extend_lags" or "locf", then the previous +#> `step_epi_lag`s won't work with modified data. }\if{html}{\out{
}} If you create columns that you then apply lags to (such as