diff --git a/R/epi_recipe.R b/R/epi_recipe.R index d33292131..bea7604e2 100644 --- a/R/epi_recipe.R +++ b/R/epi_recipe.R @@ -404,19 +404,23 @@ adjust_epi_recipe.epi_recipe <- function( x$steps[[which_step]] <- update(x$steps[[which_step]], ...) } else { step_names <- map_chr(x$steps, ~ attr(.x, "class")[1]) + starts_with_step <- substr(which_step, 1, 5) == "step_" + if (!starts_with_step) which_step <- paste0("step_", which_step) if (!(which_step %in% step_names)) { - cli::cli_abort( - c("`which_step` is not in the `epi_recipe` step names. ", - "i" = "The step names are {step_names}." - ) - ) + cli::cli_abort(c( + "`which_step` does not appear in the available `epi_recipe` step names. ", + i = "The step names are {.val {step_names}}." + )) } which_step_idx <- which(step_names == which_step) if (length(which_step_idx) == 1) { x$steps[[which_step_idx]] <- update(x$steps[[which_step_idx]], ...) } else { - cli::cli_abort("`which_step` is not unique. Matches steps: {which_step_idx}.") + cli::cli_abort(c( + "`which_step` is not unique. Matches steps: {.val {which_step_idx}}.", + i = "Please use the step number instead for precise alterations." + )) } } x @@ -444,7 +448,7 @@ prep.epi_recipe <- function( } skippers <- map_lgl(x$steps, recipes:::is_skipable) if (any(skippers) & !retain) { - rlang::warn(c( + cli::cli_warn(c( "Since some operations have `skip = TRUE`, using ", "`retain = TRUE` will allow those steps results to ", "be accessible." @@ -477,7 +481,7 @@ prep.epi_recipe <- function( ) training <- bake(x$steps[[i]], new_data = training) if (!tibble::is_tibble(training)) { - abort("bake() methods should always return tibbles") + cli::cli_abort("`bake()` methods should always return {.cls tibble}.") } if (!is_epi_df(training)) { # tidymodels killed our class diff --git a/R/frosting.R b/R/frosting.R index 90248f191..29d5359f1 100644 --- a/R/frosting.R +++ b/R/frosting.R @@ -186,19 +186,23 @@ adjust_frosting.frosting <- function( x$layers[[which_layer]] <- update(x$layers[[which_layer]], ...) } else { layer_names <- map_chr(x$layers, ~ attr(.x, "class")[1]) + starts_with_layer <- substr(which_layer, 1, 6) == "layer_" + if (!starts_with_layer) which_layer <- paste0("layer_", which_layer) if (!(which_layer %in% layer_names)) { - cli::cli_abort( - c("`which_layer` is not in the `frosting` layer names. ", - "i" = "The layer names are {layer_names}." - ) - ) + cli::cli_abort(c( + "`which_layer` does not appear in the available `frosting` layer names. ", + i = "The layer names are {.val {layer_names}}." + )) } which_layer_idx <- which(layer_names == which_layer) if (length(which_layer_idx) == 1) { x$layers[[which_layer_idx]] <- update(x$layers[[which_layer_idx]], ...) } else { - cli::cli_abort("`which_layer` is not unique. Matches layers: {which_layer_idx}.") + cli::cli_abort(c( + "`which_layer` is not unique. Matches layers: {.val {which_layer_idx}}.", + i = "Please use the layer number instead for precise alterations." + )) } } x @@ -212,7 +216,7 @@ add_postprocessor <- function(x, postprocessor, ..., call = caller_env()) { if (is_frosting(postprocessor)) { return(add_frosting(x, postprocessor)) } - rlang::abort("`postprocessor` must be a frosting object.", call = call) + cli::cli_abort("`postprocessor` must be a frosting object.", call = call) } is_frosting <- function(x) { @@ -223,8 +227,8 @@ is_frosting <- function(x) { validate_frosting <- function(x, ..., arg = "`x`", call = caller_env()) { rlang::check_dots_empty() if (!is_frosting(x)) { - glubort( - "{arg} must be a frosting postprocessor, not a {class(x)[[1]]}.", + cli::cli_abort( + "{arg} must be a frosting postprocessor, not a {.cls {class(x)[[1]]}}.", .call = call ) } @@ -283,10 +287,9 @@ new_frosting <- function() { #' p frosting <- function(layers = NULL, requirements = NULL) { if (!is_null(layers) || !is_null(requirements)) { - rlang::abort(c( - "Currently, no arguments to `frosting()` are allowed", - "to be non-null." - )) + cli::cli_abort( + "Currently, no arguments to `frosting()` are allowed to be non-null." + ) } out <- new_frosting() } @@ -305,7 +308,8 @@ extract_frosting <- function(x, ...) { #' @export extract_frosting.default <- function(x, ...) { - abort(c("Frosting is only available for epi_workflows currently.", + cli::cli_abort(c( + "Frosting is only available for epi_workflows currently.", i = "Can you use `epi_workflow()` instead of `workflow()`?" )) invisible(x) @@ -339,7 +343,8 @@ apply_frosting <- function(workflow, ...) { #' @export apply_frosting.default <- function(workflow, components, ...) { if (has_postprocessor(workflow)) { - abort(c("Postprocessing is only available for epi_workflows currently.", + cli::cli_abort(c( + "Postprocessing is only available for epi_workflows currently.", i = "Can you use `epi_workflow()` instead of `workflow()`?" )) } @@ -367,8 +372,8 @@ apply_frosting.epi_workflow <- } if (!has_postprocessor_frosting(workflow)) { - rlang::warn(c( - "Only postprocessors of class frosting are allowed.", + cli::cli_warn(c( + "Only postprocessors of class {.cls frosting} are allowed.", "Returning unpostprocessed predictions." )) components$predictions <- predict( diff --git a/R/tidy.R b/R/tidy.R index f1e4fcb67..06835eff0 100644 --- a/R/tidy.R +++ b/R/tidy.R @@ -103,13 +103,9 @@ tidy.frosting <- function(x, number = NA, id = NA, ...) { res } -#' @rdname tidy.layer #' @export tidy.layer <- function(x, ...) { - rlang::abort( - paste0( - "No `tidy` method for a layer with classes: ", - paste0(class(x), collapse = ", ") - ) + cli::cli_abort( + "No `tidy()` method exists for a layer with class: {.cls {class(x)}}." ) } diff --git a/_pkgdown.yml b/_pkgdown.yml index 964a9b80b..eef656e9d 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -48,6 +48,8 @@ reference: - epi_recipe - epi_workflow - add_epi_recipe + - adjust_epi_recipe + - add_model - predict.epi_workflow - fit.epi_workflow - augment.epi_workflow @@ -62,6 +64,7 @@ reference: - frosting - ends_with("_frosting") - get_test_data + - tidy.frosting - title: Frosting layers contents: - contains("layer") diff --git a/add_model.Rd b/add_model.Rd deleted file mode 100644 index e69de29bb..000000000