diff --git a/R/acquisition.R b/R/acquisition.R index 5235ab43..c25c5952 100644 --- a/R/acquisition.R +++ b/R/acquisition.R @@ -47,7 +47,7 @@ #' @export prob_improve <- function(trade_off = 0, eps = .Machine$double.eps) { if (!is.numeric(trade_off) & !is_function(trade_off)) { - rlang::abort("`trade_off` should be a number or a function.") + cli::cli_abort("{.arg trade_off} should be a number or a function.") } lab <- "the probability of improvement" @@ -55,7 +55,7 @@ prob_improve <- function(trade_off = 0, eps = .Machine$double.eps) { if (rlang::is_function(trade_off)) { farg <- names(formals(trade_off)) if (length(farg) == 0) { - rlang::abort("The `trade_off` function should have at least one argument.") + cli::cli_abort("The {.fn trade_off} function should have at least one argument.") } lab <- paste(lab, "with variable trade-off values.") } @@ -107,7 +107,7 @@ predict.prob_improve <- #' @rdname prob_improve exp_improve <- function(trade_off = 0, eps = .Machine$double.eps) { if (!is.numeric(trade_off) & !is_function(trade_off)) { - rlang::abort("`trade_off` should be a number or a function.") + cli::cli_abort("{.arg trade_off} should be a number or a function.") } lab <- "the expected improvement" @@ -115,7 +115,7 @@ exp_improve <- function(trade_off = 0, eps = .Machine$double.eps) { if (rlang::is_function(trade_off)) { farg <- names(formals(trade_off)) if (length(farg) == 0) { - rlang::abort("The `trade_off` function should have at least one argument.") + cli::cli_abort("The {.fn trade_off} function should have at least one argument.") } lab <- paste(lab, "with variable trade-off values.") } @@ -161,13 +161,13 @@ predict.exp_improve <- function(object, new_data, maximize, iter, best, ...) { #' @rdname prob_improve conf_bound <- function(kappa = 0.1) { if (!is.numeric(kappa) & !is_function(kappa)) { - rlang::abort("`kappa` should be a number or a function.") + cli::cli_abort("{.arg kappa} should be a number or a function.") } lab <- "the confidence bound" if (rlang::is_function(kappa)) { farg <- names(formals(kappa)) if (length(farg) == 0) { - rlang::abort("The `trade_off` function should have at least one argument.") + cli::cli_abort("The {.fn trade_off} function should have at least one argument.") } lab <- paste(lab, "with variable kappa values.") } diff --git a/R/augment.R b/R/augment.R index 2ca56fc0..d0ab84d5 100644 --- a/R/augment.R +++ b/R/augment.R @@ -49,7 +49,7 @@ augment.tune_results <- function(x, ..., parameters = NULL) { parameters <- select_best(x, metric = obj_fun, eval_time = obj_eval_time) } else { if (!is.data.frame(parameters) || nrow(parameters) > 1) { - rlang::abort("'parameters' should be a single row data frame") + cli::cli_abort("{.arg parameters} should be a single row data frame.") } } @@ -86,11 +86,9 @@ merge_pred <- function(dat, pred, y) { pred <- pred[order(pred$.row), ] pred <- pred[, c(".row", pred_cols)] if (nrow(pred) != nrow(dat)) { - rlang::warn( - paste( - "The original data had", nrow(dat), "rows but there were", - nrow(pred), "hold-out predictions." - ) + cli::cli_warn( + "The original data had {nrow(dat)} rows but there were {nrow(pred)} + hold-out predictions." ) } diff --git a/R/case_weights.R b/R/case_weights.R index b53309f6..a17147f2 100644 --- a/R/case_weights.R +++ b/R/case_weights.R @@ -26,15 +26,17 @@ #' @export .use_case_weights_with_yardstick.default <- function(x) { message <- c( - paste0("Unknown case weights object with class <", class(x)[[1]], ">. "), + "An object with {.cls hardhat_case_weights} was expected, not + {.obj_type_friendly {x}}.", i = paste0( - "Define a `.use_case_weights_with_yardstick()` method for this type to ", - "declare whether or not these case weights should be passed on to yardstick." + "Define a {.fn .use_case_weights_with_yardstick} method for this type to ", + "declare whether or not these case weights should be passed on to + {.pkg yardstick}." ), - i = "See `?.use_case_weights_with_yardstick` for more information." + i = "See {.help .use_case_weights_with_yardstick} for more information." ) - rlang::abort(message) + cli::cli_abort(message) } #' @rdname dot-use_case_weights_with_yardstick @@ -55,7 +57,7 @@ extract_case_weights <- function(data, workflow) { col <- extract_case_weights_col(workflow) if (!rlang::is_quosure(col)) { - rlang::abort("`col` must exist and be a quosure at this point.", .internal = TRUE) + cli::cli_abort("{.arg col} must exist and be a quosure at this point.", .internal = TRUE) } loc <- eval_select_case_weights(col, data) @@ -63,10 +65,10 @@ extract_case_weights <- function(data, workflow) { case_weights <- data[[loc]] if (!hardhat::is_case_weights(case_weights)) { - rlang::abort(paste0( - "Case weights must be a supported case weights type, as determined by ", - "`hardhat::is_case_weights()`." - )) + cli::cli_abort( + "Case weights must be a supported case weights type, as determined by + {.fn hardhat::is_case_weights}." + ) } case_weights @@ -96,12 +98,11 @@ eval_select_case_weights <- function(col, ) if (length(loc) != 1L) { - message <- paste0( - "`col` must specify exactly one column from ", - "`data` to extract case weights from." + cli::cli_abort( + "{.arg col} must specify exactly one column from {.arg data} to + extract case weights from.", + call = call ) - - rlang::abort(message, call = call) } loc diff --git a/R/checks.R b/R/checks.R index f2e209a9..b7111a34 100644 --- a/R/checks.R +++ b/R/checks.R @@ -3,38 +3,39 @@ #' @rdname empty_ellipses check_rset <- function(x) { if (!inherits(x, "rset")) { - rlang::abort(paste0( - "The `resamples` argument should be an 'rset' object, such as the type ", - "produced by `vfold_cv()` or other 'rsample' functions." - )) + cli::cli_abort( + c( + "The {.arg resamples} argument should be an {.cls rset} object,", + "i" = "Such objects are produced by {.fn vfold_cv} or other + {.pkg rsample} functions." + ) + ) } if (inherits(x, "loo_cv")) { - rlang::abort( - "Leave-one-out cross-validation is not currently supported with tune." - ) + cli::cli_abort("Leave-one-out cross-validation is not currently supported with {.pkg tune}.") } if (inherits(x, "nested_cv")) { - rlang::abort("Nested resampling is not currently supported with tune.") + cli::cli_abort("Nested resampling is not currently supported with tune.") } if (inherits(x, "permutations")) { - rlang::abort("Permutation samples are not suitable for tuning.") + cli::cli_abort("Permutation samples are not suitable for tuning.") } invisible(NULL) } -backend_options_msg <- "`backend_options` should be created by `tune::new_backend_options()`." +backend_options_msg <- "{.arg backend_options} should be created by {.fn tune::new_backend_options}." check_backend_options <- function(backend_options) { if (!is.null(backend_options) && !inherits(backend_options, "tune_backend_options")) { - rlang::abort(backend_options_msg) + cli::cli_abort(backend_options_msg) } invisible(NULL) } -grid_msg <- "`grid` should be a positive integer or a data frame." +grid_msg <- "{.arg grid} should be a positive integer or a data frame." check_grid <- function(grid, workflow, pset = NULL, call = caller_env()) { # `NULL` grid is the signal that we are using `fit_resamples()` @@ -47,12 +48,11 @@ check_grid <- function(grid, workflow, pset = NULL, call = caller_env()) { } if (nrow(pset) == 0L) { - msg <- paste0( - "No tuning parameters have been detected, ", - "performance will be evaluated using the resamples with no tuning. ", - "Did you want to [tune()] parameters?" - ) - rlang::warn(msg) + cli::cli_warn(c( + "No tuning parameters have been detected, performance will be + evaluated using the resamples with no tuning.", + "Did you want to assign any parameters with a value of {.fn tune}?" + )) # Return `NULL` as the new `grid`, like what is used in `fit_resamples()` return(NULL) @@ -60,7 +60,7 @@ check_grid <- function(grid, workflow, pset = NULL, call = caller_env()) { if (!is.numeric(grid)) { if (!is.data.frame(grid)) { - rlang::abort(grid_msg) + cli::cli_abort(grid_msg) } grid_distinct <- distinct(grid) @@ -69,7 +69,7 @@ check_grid <- function(grid, workflow, pset = NULL, call = caller_env()) { grid_distinct <- vctrs::new_data_frame(grid_distinct, n = nrow(grid_distinct)) if (!identical(nrow(grid_distinct), nrow(grid))) { - rlang::warn( + cli::cli_warn( "Duplicate rows in grid of tuning combinations found and removed." ) } @@ -87,32 +87,28 @@ check_grid <- function(grid, workflow, pset = NULL, call = caller_env()) { extra_tune_params <- setdiff(tune_params, grid_params) if (length(extra_grid_params) != 0L) { - extra_grid_params <- glue::single_quote(extra_grid_params) - extra_grid_params <- glue::glue_collapse(extra_grid_params, sep = ", ") + n_extra <- length(extra_grid_params) - msg <- glue::glue( - "The provided `grid` has the following parameter columns that have ", - "not been marked for tuning by `tune()`: {extra_grid_params}." + cli::cli_abort( + "The provided grid has {n_extra} parameter column{?s} + ({.var {extra_grid_params}}) that {?has/have} not been marked for tuning + by {.fn tune}." ) - - rlang::abort(msg) } if (length(extra_tune_params) != 0L) { - extra_tune_params <- glue::single_quote(extra_tune_params) - extra_tune_params <- glue::glue_collapse(extra_tune_params, sep = ", ") + n_extra <- length(extra_tune_params) - msg <- glue::glue( - "The provided `grid` is missing the following parameter columns that ", - "have been marked for tuning by `tune()`: {extra_tune_params}." + cli::cli_abort( + "The provided grid is missing the following {n_extra} parameter + column{?s} that {?has/have} been marked for tuning by {.fn tune}: + {.val {extra_tune_params}}." ) - - rlang::abort(msg) } } else { grid <- as.integer(grid[1]) if (grid < 1) { - rlang::abort(grid_msg) + cli::cli_abort(grid_msg) } check_workflow(workflow, pset = pset, check_dials = TRUE, call = call) @@ -158,22 +154,21 @@ check_parameters <- function(wflow, pset = NULL, data, grid_names = character(0) if (needs_finalization(pset, grid_names)) { if (tune_recipe) { - rlang::abort( - paste( - "Some model parameters require finalization but there are recipe", - "parameters that require tuning. Please use ", - "`extract_parameter_set_dials()` to set parameter ranges ", - "manually and supply the output to the `param_info` argument." + cli::cli_abort( + c( + "Some model parameters require finalization but there are recipe + parameters that require tuning.", + "i" = "Please use {.fn extract_parameter_set_dials} to set parameter + ranges manually and supply the output to the {.arg param_info} + argument." ) ) } - msg <- "Creating pre-processing data to finalize unknown parameter" unk_names <- pset$id[unk] - if (length(unk_names) == 1) { - msg <- paste0(msg, ": ", unk_names) - } else { - msg <- paste0(msg, "s: ", paste0("'", unk_names, "'", collapse = ", ")) - } + num_unk <- length(unk_names) + msg <- + cli::format_inline( + "Creating pre-processing data to finalize {num_unk} unknown parameter{?s}: {.val {unk_names}}") tune_log(list(verbose = TRUE), split_labels = NULL, msg, type = "info") @@ -194,7 +189,7 @@ is_installed <- function(pkg) { check_installs <- function(x, call = caller_env()) { if (x$engine == "unknown") { - rlang::abort("Please declare an engine for the model") + cli::cli_abort("Please declare an engine for the model") } else { m_type <- class(x)[1] deps <- parsnip::get_dependency(m_type) @@ -207,7 +202,7 @@ check_installs <- function(x, call = caller_env()) { if (any(!is_inst)) { needs_installed <- unique(deps[!is_inst]) cli::cli_abort( - "{cli::qty(needs_installed)} Package install{?s} {?is/are} \\ + "{cli::qty(needs_installed)} Package install{?s} {?is/are} required for {.pkg {needs_installed}}.", call = call ) @@ -218,44 +213,39 @@ check_installs <- function(x, call = caller_env()) { check_bayes_initial_size <- function(num_param, num_grid, race = FALSE) { msg <- cli::pluralize( - "There {cli::qty(num_param)}{?is/are} {num_param} tuning parameter{?s} \\ + "There {cli::qty(num_param)}{?is/are} {num_param} tuning parameter{?s} and {num_grid} grid point{?s} {?was/were} requested." ) + msg_list <- c( + "{msg}", + "i" = "The GP model requires 2+ initial points. For best performance, + supply more initial points than there are tuning parameters." + ) + bullet_msg <- + c( + `!` = "{msg}", + `*` = cli::pluralize( + "There are {cli::qty(diff)}{?as many/more} tuning parameters + {cli::qty(diff)}{?as/than} there are initial points. + This is likely to cause numerical issues in the first few + search iterations.") + ) + if (race) { race_msg <- "With racing, only completely resampled parameters are used." - } else { - race_msg <- NULL + msg_list <- c(msg_list, "i" = race_msg) + bullet_msg <- c(bullet_msg, `*` = race_msg) } if (num_grid == 1) { - rlang::abort( - c( - msg, - glue::glue( - "The GP model requires 2+ initial points. For best performance, \\ - supply more initial points than there are tuning parameters." - ), - race_msg - ), - call = NULL - ) + cli::cli_abort(msg_list) } if (num_grid < num_param + 1) { diff <- num_param - num_grid + 1 - cli::cli_bullets( - c( - `!` = msg, - `*` = cli::pluralize( - "There are {cli::qty(diff)}{?as many/more} tuning parameters \\ - {cli::qty(diff)}{?as/than} there are initial points. \\ - This is likely to cause numerical issues in the first few \\ - search iterations."), - `*` = race_msg - ) - ) + cli::cli_bullets(bullet_msg) } invisible(NULL) @@ -265,11 +255,10 @@ check_param_objects <- function(pset) { params <- purrr::map_lgl(pset$object, inherits, "param") if (!all(params)) { - rlang::abort(paste0( - "The workflow has arguments to be tuned that are missing some ", - "parameter objects: ", - paste0("'", pset$id[!params], "'", collapse = ", ") - )) + cli::cli_abort( + "The workflow has arguments to be tuned that are missing some parameter + objects: {.val {pset$id[!params]}}" + ) } invisible(pset) } @@ -280,15 +269,15 @@ check_param_objects <- function(pset) { #' @param check_dials A logical for check for a NULL parameter object. check_workflow <- function(x, ..., pset = NULL, check_dials = FALSE, call = caller_env()) { if (!inherits(x, "workflow")) { - rlang::abort("The `object` argument should be a 'workflow' object.") + cli::cli_abort("The {.arg object} argument should be a {.cls workflow} object.") } if (!has_preprocessor(x)) { - rlang::abort("A formula, recipe, or variables preprocessor is required.") + cli::cli_abort("A formula, recipe, or variables preprocessor is required.") } if (!has_spec(x)) { - rlang::abort("A parsnip model is required.") + cli::cli_abort("A parsnip model is required.") } rlang::check_dots_empty(call = call) @@ -303,10 +292,10 @@ check_workflow <- function(x, ..., pset = NULL, check_dials = FALSE, call = call incompl <- dials::has_unknowns(pset$object) if (any(incompl)) { - rlang::abort(paste0( - "The workflow has arguments whose ranges are not finalized: ", - paste0("'", pset$id[incompl], "'", collapse = ", ") - )) + cli::cli_abort( + "The workflow has arguments whose ranges are not finalized: + {.val {pset$id[incompl]}}." + ) } } @@ -359,9 +348,10 @@ check_metrics <- function(x, object) { x <- yardstick::metric_set(brier_survival) }, unknown = { - rlang::abort("Internal error: `check_installs()` should have caught an `unknown` mode.") + cli::cli_abort("Internal error: {.fn check_installs} should have + caught an {.val unknown} mode.") }, - rlang::abort("Unknown `mode` for parsnip model.") + cli::cli_abort("Unknown {.val mode} for parsnip model.") ) return(x) @@ -372,37 +362,37 @@ check_metrics <- function(x, object) { is_surv_metric_set <- inherits(x, c("survival_metric_set")) if (!is_numeric_metric_set && !is_class_prob_metric_set && !is_surv_metric_set) { - rlang::abort("The `metrics` argument should be the results of [yardstick::metric_set()].") + cli::cli_abort("The {.arg metrics} argument should be the results of + {.fn yardstick::metric_set}.") } if (mode == "regression" && !is_numeric_metric_set) { - msg <- paste0( - "The parsnip model has `mode = 'regression'`, ", - "but `metrics` is a metric set for a different model mode." + cli::cli_abort( + c( + "The parsnip model has {.code mode = 'regression'}, but {.arg metrics} + is a metric set for a different model mode." + ) ) - rlang::abort(msg) } if (mode == "classification" && !is_class_prob_metric_set) { - msg <- paste0( - "The parsnip model has `mode = 'classification'`, ", - "but `metrics` is a metric set for a different model mode." + cli::cli_abort( + c( + "The parsnip model has {.code mode = 'classification'}, but {.arg metrics} + is a metric set for a different model mode." + ) ) - rlang::abort(msg) } if (mode == "censored regression" && !is_surv_metric_set) { - msg <- paste0( - "The parsnip model has `mode = 'censored regression'`, ", - "but `metrics` is a metric set for a different model mode." - ) - rlang::abort(msg) + cli::cli_abort(c( + "The parsnip model has {.code mode = 'censored regression'}, + but {.arg metrics} is a metric set for a different model mode." + )) } x } -bayes_msg <- "`initial` should be a positive integer or the results of [tune_grid()]" - #' @export #' @keywords internal #' @rdname empty_ellipses @@ -418,13 +408,14 @@ check_initial <- function(x, ctrl, checks = "grid") { if (is.null(x)) { - rlang::abort(bayes_msg) + cli::cli_abort("{.arg initial} should be a positive integer or the results + of {.fn tune_grid}") } if (is.numeric(x)) { x <- create_initial_set(pset, n = x, checks = checks) if (ctrl$verbose) { message() - msg <- paste0(" Generating a set of ", nrow(x), " initial parameter results") + msg <- cli::format_inline(" Generating a set of {nrow(x)} initial parameter results") tune_log(ctrl, split_labels = NULL, msg, type = "go") } @@ -446,13 +437,16 @@ check_initial <- function(x, } } else { if (!inherits(x, "tune_results")) { - rlang::abort(bayes_msg) + cli::cli_abort("{.arg initial} should be a positive integer or the results + of {.fn tune_grid}") } if (ctrl$save_pred & !any(names(x) == ".predictions")) { - rlang::abort("`save_pred` can only be used if the initial results saved predictions.") + cli::cli_abort("{.arg save_pred} can only be used if the initial results + saved predictions.") } if (!is.null(ctrl$extract) & !any(names(x) == ".extracts")) { - rlang::abort("`extract` can only be used if the initial results has extractions.") + cli::cli_abort("The {.fn extract} function can only be used if the initial + results have extractions.") } param_nms <- .get_tune_parameter_names(x) if (inherits(x, "tune_race")) { @@ -565,9 +559,9 @@ check_gp_data <- function(x) { n_uni <- length(unique(x$mean)) if (n_uni == 1) { - msg <- glue::glue( + msg <- cli::pluralize( "All of the {met} values were identical. The Gaussian process model cannot - be fit to the data. Try expanding the range of the tuning parameters." + be fit to the data. Try expanding the range of the tuning parameters." ) message_wrap(msg, prefix = "!", color_text = get_tune_colors()$message$danger) } @@ -583,7 +577,7 @@ check_gp_failure <- function(current, prev) { # first model failed or all previous models failed if (is.null(prev) || inherits(prev, "try-error")) { - rlang::abort("Gaussian process model was not fit.") + cli::cli_abort("Gaussian process model was not fit.") } # return prev model @@ -597,12 +591,12 @@ check_no_tuning <- function(x) { return(invisible(FALSE)) } srcs <- unique(tune_param$source) - num_srcs <- length(srcs) - srcs <- paste0(srcs, collapse = " and ") - msg_1 <- cli::pluralize("{num_param} argument{?s} {?has/have} been tagged for tuning in {?this component/these components}: {srcs}. ") - msg_2 <- "Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them." - msg <- paste(msg_1, msg_2, sep = "\n") - rlang::abort(msg, call = NULL) + cli::cli_abort(c( + "{num_param} argument{?s} {?has/have} been tagged for tuning in + {?this component/these components}: {srcs}.", + "i" = "Please use one of the tuning functions (e.g. {.fn tune_grid}) + to optimize them." + )) } dyn_inputs <- c("integrated_survival_metric", "dynamic_survival_metric") @@ -617,8 +611,9 @@ check_eval_time <- function(eval_time, metrics) { ) } if (is.null(eval_time) & needs_eval_time) { - rlang::abort( - "One or more metric requires the specification of time points in the `eval_time` argument.", + cli::cli_abort( + "One or more metric requires the specification of time points in the + {.arg eval_time} argument.", call = NULL ) } diff --git a/R/collect.R b/R/collect.R index c3442160..b61ca8e9 100644 --- a/R/collect.R +++ b/R/collect.R @@ -152,12 +152,10 @@ collect_predictions.tune_results <- function(x, ..., summarize = FALSE, paramete has_coll_col <- coll_col %in% names if (!has_coll_col) { - msg <- paste0( - "The `.predictions` column does not exist. ", - "Refit with the control argument `save_pred = TRUE` to save predictions." + cli::cli_abort( + "The {.field .predictions} column does not exist. Please refit with the + control argument {.code save_pred = TRUE} to save predictions." ) - - rlang::abort(msg) } x <- filter_predictions(x, parameters) @@ -183,17 +181,9 @@ filter_predictions <- function(x, parameters) { } params <- attr(x, "parameters") if (is.null(params)) { - rlang::warn( - paste( - strwrap( - paste( - "The object is missing some attributes; it is probably from", - "an earlier version of `tune`. The predictions can't be filtered." - ), - prefix = "" - ), - collapse = "\n" - ) + cli::cli_warn( + "The object is missing some attributes; it is probably from an earlier + version of {.pkg tune}. The predictions can't be filtered." ) return(x) @@ -202,12 +192,8 @@ filter_predictions <- function(x, parameters) { param_names <- params$id parameters <- dplyr::select(parameters, dplyr::any_of(param_names)) if (ncol(parameters) != length(param_names)) { - rlang::abort( - paste0( - "`parameters` should only have columns: ", - paste0("'", param_names, "'", collapse = ", ") - ) - ) + cli::cli_abort("{.arg parameters} should only have columns: + {.val {param_names}}.") } x$.predictions <- purrr::map(x$.predictions, dplyr::inner_join, parameters, by = param_names) @@ -400,12 +386,7 @@ average_predictions <- function(x, grid = NULL) { if (!is.null(grid)) { grid <- dplyr::select(grid, dplyr::all_of(param_names)) if (ncol(grid) != length(param_names)) { - rlang::abort( - paste0( - "`grid` should only have columns: ", - paste0("'", param_names, "'", collapse = ", ") - ) - ) + cli::cli_abort("{.arg grid} should only have columns: {.val {param_names}}.") } x$.predictions <- purrr::map(x$.predictions, dplyr::inner_join, grid, by = param_names) @@ -429,11 +410,9 @@ average_predictions <- function(x, grid = NULL) { } else if (any(metric_types %in% c("survival", "time"))) { x <- surv_summarize(x, param_names, y_nms) } else { - msg <- paste( - "We don't know about metrics of type:", - paste(unique(metric_types), collapse = ", ") + cli::cli_abort( + "We don't know about metrics of type: {.val {unique(metric_types)}}." ) - rlang::abort(msg) } if (dplyr::is_grouped_df(x)) { @@ -566,7 +545,10 @@ estimate_tune_results <- function(x, ..., col_name = ".metrics") { all_bad <- is_cataclysmic(x) if (all_bad) { - rlang::abort("All models failed. Run `show_notes(.Last.tune.result)` for more information.") + cli::cli_abort( + "All models failed. Run {.code show_notes(.Last.tune.result)} for more + information." + ) } # The mapping of tuning parameters and .config. diff --git a/R/compat-vctrs.R b/R/compat-vctrs.R index 5db8591d..a49c5651 100644 --- a/R/compat-vctrs.R +++ b/R/compat-vctrs.R @@ -175,5 +175,5 @@ stop_incompatible_cast_iteration_results <- function(x, to, ..., x_arg = "", to_ } stop_never_called <- function(fn) { - rlang::abort(paste0("Internal error: `", fn, "()` should never be called.")) + cli::cli_abort("Internal error: {.fn {fn}} should never be called.") } diff --git a/R/compute_metrics.R b/R/compute_metrics.R index 94690e90..b62727f6 100644 --- a/R/compute_metrics.R +++ b/R/compute_metrics.R @@ -76,7 +76,8 @@ compute_metrics.default <- function(x, summarize = TRUE, event_level = "first", ...) { - rlang::abort("No `compute_metrics()` method exists for this type of object.") + cli::cli_abort("No {.fn compute_metrics} method exists for + {.obj_type_friendly {x}}.") } #' @export @@ -89,14 +90,14 @@ compute_metrics.tune_results <- function(x, rlang::check_dots_empty() check_bool(summarize) if (!".predictions" %in% names(x)) { - rlang::abort(paste0( - "`x` must have been generated with the ", - "control argument `save_pred = TRUE`." - )) + cli::cli_abort( + "{.arg x} must have been generated with the control argument + {.code save_pred = TRUE}." + ) } if (!inherits(metrics, "metric_set")) { - rlang::abort("`metrics` must be a metric set.") + cli::cli_abort("{.arg metrics} must be a metric set.") } new_metrics_info <- metrics_info(metrics) diff --git a/R/conf_mat_resampled.R b/R/conf_mat_resampled.R index 49b1e7ef..f6e9fc5f 100644 --- a/R/conf_mat_resampled.R +++ b/R/conf_mat_resampled.R @@ -36,22 +36,21 @@ conf_mat_resampled <- function(x, ..., parameters = NULL, tidy = TRUE) { rlang::check_dots_empty() if (!inherits(x, "tune_results")) { - rlang::abort( - "The first argument needs to be an object with class 'tune_results'." - ) + cli::cli_abort("The first argument needs to be {.cls tune_results} object, + not {.obj_type_friendly {mtcars}}.") } if (!any(names(x) == ".predictions")) { - rlang::abort( - paste0( - "The function was not run with the `save_pred = TRUE` option. ", - "Please re-run with that option." - ) + cli::cli_abort( + "The function was not run with the {.code save_pred = TRUE} option. + Please re-run with that option." ) } preds <- collect_predictions(x, summarize = FALSE, parameters = parameters) if (!any(names(preds) == ".pred_class")) { - rlang::abort("Cannot find the predicted classes. Was this a classification model?") + cli::cli_abort( + "Cannot find the predicted classes. Was this a classification model?" + ) } # check for multiple parameter combinations params <- .get_tune_parameter_names(x) @@ -61,19 +60,17 @@ conf_mat_resampled <- function(x, ..., parameters = NULL, tidy = TRUE) { dplyr::select(!!!params) %>% distinct() if (nrow(param_combos) > 1) { - rlang::abort( - paste0( - "It looks like there are ", nrow(param_combos), " tuning parameter ", - "combination(s) in the data. Please use the `parameters` ", - "argument to select one combination of parameters." - ) + cli::cli_abort( + "It looks like there are {nrow(param_combos)} tuning parameter + combination in the data. Please use the {.arg parameters} + argument to select one combination of parameters." ) } } truth <- .get_tune_outcome_names(x) if (length(truth) != 1) { - rlang::abort("Cannot determine the proper outcome name") + cli::cli_abort("Cannot determine the proper outcome name") } id_cols <- grep("(^id$)|($id[1-9]$)", names(preds), value = TRUE) diff --git a/R/control.R b/R/control.R index 9dc69d6c..fded0799 100644 --- a/R/control.R +++ b/R/control.R @@ -312,7 +312,7 @@ new_backend_options <- function(..., class = character()) { out <- rlang::list2(...) if (any(rlang::names2(out) == "")) { - rlang::abort("All backend options must be named.") + cli::cli_abort("All backend options must be named.") } structure(out, class = c(class, "tune_backend_options")) diff --git a/R/extract.R b/R/extract.R index 0a167f1e..8c6e51c2 100644 --- a/R/extract.R +++ b/R/extract.R @@ -115,10 +115,13 @@ extract_recipe.tune_results <- function(x, ..., estimated = TRUE) { check_empty_dots <- function(...) { opts <- list(...) if (any(names(opts) == "estimated")) { - rlang::abort("'estimated' should be a named argument.") + cli::cli_abort("'{.arg estimated}' should be a named argument.") } if (length(opts) > 0) { - rlang::abort("'...' are not used in this function.") + cli::cli_warn( + "The {.code ...} are not used in this function but {length(opts)} + object{?s} {?was/were} passed: {.val {names(opts)}}" + ) } invisible(NULL) } diff --git a/R/filter_parameters.R b/R/filter_parameters.R index afff0fc2..0658c068 100644 --- a/R/filter_parameters.R +++ b/R/filter_parameters.R @@ -57,7 +57,8 @@ filter_parameters <- function(x, ..., parameters = NULL) { check_filter_dots(rlang::enquos(...)) # check for type if (!inherits(x, "tune_results")) { - rlang::abort(paste0(cl_x, " should have class 'tune_results'.")) + cli::cli_abort("{.arg {caller_arg(x)}} should have class {.cls tune_results}; + {.obj_type_friendly {x}} was passed.") } x <- filter_by_join(x, parameters, nm = cl_x) x <- filter_by_filter(x, ...) @@ -73,11 +74,9 @@ filter_by_join <- function(x, parameters = NULL, nm = "") { filter_names <- names(parameters) filter_names <- filter_names[filter_names != ".config"] if (length(intersect(filter_names, param_names)) == 0) { - msg <- paste0( - "There are no columns in 'parameters' that match with ", - as.character(nm) + cli::cli_abort( + "There are no columns in {.arg parameters} that match with {.val {nm}}." ) - rlang::abort(msg) } extra_names <- setdiff(filter_names, param_names) if (length(extra_names) > 0) { @@ -93,7 +92,7 @@ filter_by_join <- function(x, parameters = NULL, nm = "") { tst_orig <- bind_rows(x$.metrics) tst_filtered <- filter_join_iter(tst_orig, parameters) if (nrow(tst_filtered) == 0) { - rlang::abort("No parameter combinations were selected using your subset.") + cli::cli_abort("No parameter combinations were selected using your subset.") } x$.metrics <- purrr::map(x$.metrics, filter_join_iter, .subset = parameters) @@ -133,9 +132,12 @@ check_filter_dots <- function(dots, call = rlang::caller_env()) { res <- purrr::map(dots, ~try(rlang::eval_tidy(.x), silent = TRUE)) if (any(purrr::map_lgl(res, inherits, "data.frame"))) { - rlang::abort( - c("An element passed to `...` is a data frame rather than a filter expression.", - "i" = "Did you forget to name the `parameters` argument?"), + cli::cli_abort( + c( + "An element passed to {.arg ...} is a data frame rather than a filter + expression.", + "i" = "Did you forget to name the {.arg parameters} argument?" + ), call = call ) } diff --git a/R/finalize.R b/R/finalize.R index a3f9b073..a0c365b4 100644 --- a/R/finalize.R +++ b/R/finalize.R @@ -30,7 +30,8 @@ #' finalize_model(knn_model, lowest_rmse) finalize_model <- function(x, parameters) { if (!inherits(x, "model_spec")) { - rlang::abort("`x` should be a parsnip model specification.") + cli::cli_abort("{.arg x} should be a parsnip model specification, not + {.obj_type_friendly {x}}.") } check_final_param(parameters) pset <- hardhat::extract_parameter_set_dials(x) @@ -54,7 +55,7 @@ finalize_model <- function(x, parameters) { #' @rdname finalize_model finalize_recipe <- function(x, parameters) { if (!inherits(x, "recipe")) { - rlang::abort("`x` should be a recipe.") + cli::cli_abort("{.arg x} should be a recipe, not {.obj_type_friendly {x}}.") } check_final_param(parameters) pset <- @@ -80,7 +81,7 @@ finalize_recipe <- function(x, parameters) { #' @rdname finalize_model finalize_workflow <- function(x, parameters) { if (!inherits(x, "workflow")) { - rlang::abort("`x` should be a workflow") + cli::cli_abort("{.arg x} should be a workflow, not {.obj_type_friendly {x}}.") } check_final_param(parameters) @@ -101,10 +102,11 @@ finalize_workflow <- function(x, parameters) { check_final_param <- function(x) { if (!is.list(x) & !tibble::is_tibble(x)) { - rlang::abort("The parameter object should be a list or tibble") + cli::cli_abort("The parameter object should be a {.cls list} or + {.cls tibble}, not {.obj_type_friendly {x}}.") } if (tibble::is_tibble(x) && nrow(x) > 1) { - rlang::abort("The parameter tibble should have a single row.") + cli::cli_abort("The parameter {.arg tibble} should have a single row.") } invisible(x) } diff --git a/R/fit_best.R b/R/fit_best.R index 0590a303..d91b7380 100644 --- a/R/fit_best.R +++ b/R/fit_best.R @@ -78,10 +78,8 @@ fit_best <- function(x, ...) { #' @export #' @rdname fit_best fit_best.default <- function(x, ...) { - cls <- class(x) cli::cli_abort( - "There is no `fit_best()` method for an object with \\ - {cli::qty(cls)} class{?es} {.var {cls}}." + "No {.fn fit_best} exists for {.obj_type_friendly {x}}." ) } @@ -162,8 +160,9 @@ fit_best.tune_results <- function(x, } } else { if (!is.null(add_validation_set)) { - rlang::warn( - "The option `add_validation_set` is being ignored because the resampling object does not include a validation set." + cli::cli_warn( + "The option {.arg add_validation_set} is being ignored because the + resampling object does not include a validation set." ) } dat <- x$splits[[1]]$data diff --git a/R/grid_code_paths.R b/R/grid_code_paths.R index 505d6ccc..51d4f88e 100644 --- a/R/grid_code_paths.R +++ b/R/grid_code_paths.R @@ -96,7 +96,8 @@ tune_grid_loop_agua <- function(resamples, eval_time = NULL, rng) { if (!rlang::is_installed("agua")) { - rlang::abort("`agua` must be installed to use an h2o parsnip engine.") + cli::cli_abort("The {.pkg agua} package must be installed to use an h2o + parsnip engine.") } parallel_over <- control$parallel_over @@ -126,7 +127,8 @@ parallel_over_finalize_agua <- function(parallel_over) { } if (!identical(parallel_over, "resamples")) { - rlang::abort("`agua` only supports `parallel_over = \"resamples\".") + cli::cli_abort("The {.arg agua} package only supports + {.code parallel_over = 'resamples'}.") } parallel_over @@ -298,7 +300,7 @@ tune_grid_loop_impl <- function(fn_tune_grid_loop_iter, return(results) } - rlang::abort("Invalid `parallel_over`.", .internal = TRUE) + cli::cli_abort("Invalid {.arg parallel_over}.", .internal = TRUE) } # ------------------------------------------------------------------------------ diff --git a/R/grid_helpers.R b/R/grid_helpers.R index 365386d5..91b6131e 100644 --- a/R/grid_helpers.R +++ b/R/grid_helpers.R @@ -15,25 +15,22 @@ predict_model <- function(new_data, orig_rows, workflow, grid, metrics, } if (length(orig_rows) != nrow(x_vals)) { - msg <- paste0( - "Some assessment set rows are not available at ", - "prediction time. " - ) + msg <- "Some assessment set rows are not available at prediction time." if (has_preprocessor_recipe(workflow)) { - msg <- paste0( - msg, - "Consider using `skip = TRUE` on any recipe steps that remove rows ", - "to avoid calling them on the assessment set." - ) + msg <- + c( + msg, + i = + "Consider using {.code skip = TRUE} on any recipe steps that + remove rows to avoid calling them on the assessment set." + + ) } else { - msg <- paste0( - msg, - "Did your preprocessing steps filter or remove rows?" - ) + msg <- c(msg, i = "Did your preprocessing steps filter or remove rows?") } - rlang::abort(msg) + cli::cli_abort(msg) } # Determine the type of prediction that is required diff --git a/R/grid_performance.R b/R/grid_performance.R index f9983124..fcfa024a 100644 --- a/R/grid_performance.R +++ b/R/grid_performance.R @@ -76,10 +76,10 @@ metrics_info <- function(x) { types <- unique(metrics_info$type) if (length(outcome_name) > 1L) { - rlang::abort(paste0( - "Internal error: Multiple outcomes are not ", - "supported in `.estimate_metrics()`." - )) + cli::cli_abort( + "Multiple outcomes are not supported in {.fn .estimate_metrics}.", + .internal = TRUE + ) } if (case_weights_column_name() %in% names(dat)) { @@ -95,7 +95,7 @@ metrics_info <- function(x) { } else if (all(types == "time" | types == "survival")) { estimate_surv(dat, metric, param_names, outcome_name, case_weights, types) } else { - rlang::abort("Metric type not yet supported by tune.") + cli::cli_abort("Metric type not yet supported by {.pkg tune}.") } } @@ -127,7 +127,8 @@ estimate_class_prob <- function(dat, metric, param_names, outcome_name, } else if (identical(event_level, "second")) { probs <- probs[[2]] } else { - rlang::abort("`event_level` must be either 'first' or 'second'.") + cli::cli_abort("{.arg event_level} must be either {.val first} or + {.val second}.") } } } @@ -162,18 +163,18 @@ unnest_parameters <- function(x, params = NULL) { if (is.null(params)) { return(x) } - + # When multi_predict() is used, .pred will have the tuning parameter values. # Other (non-submodel) parameters will be outside of 'x'. # If this happens, pull the submodel parameters out of .pred and put them at # the out level ('x') with the rest (if any) - + outer_nms <- names(x) has_pred <- any(outer_nms == ".pred") if (!has_pred) { return(x) } - + inner_nms <- names(x$.pred[[1]]) has_inner_params <- any(params %in% inner_nms) if (!has_inner_params) { diff --git a/R/last_fit.R b/R/last_fit.R index 611d0eae..d080b752 100644 --- a/R/last_fit.R +++ b/R/last_fit.R @@ -98,11 +98,10 @@ last_fit <- function(object, ...) { #' @export last_fit.default <- function(object, ...) { - msg <- paste0( - "The first argument to [last_fit()] should be either ", - "a model or workflow." + cli::cli_abort( + "The first argument to {.fn last_fit} should be either a model or workflow, + not {.obj_type_friendly {object}}." ) - rlang::abort(msg) } #' @export @@ -117,16 +116,17 @@ last_fit.model_fit <- function(object, ...) { )) } +tune_pp_msg <- "To tune a model specification, you must preprocess with a + formula, recipe, or {.pkg dplyr} selectors, not + {.obj_type_friendly {preprocessor}}." + #' @export #' @rdname last_fit last_fit.model_spec <- function(object, preprocessor, split, ..., metrics = NULL, eval_time = NULL, control = control_last_fit(), add_validation_set = FALSE) { if (rlang::is_missing(preprocessor) || !is_preprocessor(preprocessor)) { - rlang::abort(paste( - "To tune a model spec, you must preprocess", - "with a formula or recipe" - )) + cli::cli_abort(tune_pp_msg) } control <- parsnip::condense_control(control, control_last_fit()) diff --git a/R/load_ns.R b/R/load_ns.R index 23d2cb73..c036d3d4 100644 --- a/R/load_ns.R +++ b/R/load_ns.R @@ -53,8 +53,7 @@ full_load <- c("kknn", "earth") did_load <- purrr::map_lgl(x, requireNamespace, quietly = TRUE) if (any(!did_load)) { bad <- x[!did_load] - msg <- paste0("'", bad, "'", collapse = ", ") - rlang::abort(paste("These packages could not be loaded:", msg)) + cli::cli_abort("The package{?s} {.pkg {bad}} could not be loaded.") } } diff --git a/R/logging.R b/R/logging.R index 335c66e1..448a90b3 100644 --- a/R/logging.R +++ b/R/logging.R @@ -390,7 +390,8 @@ format_msg <- function(loc, msg) { } if (!is_workflow(result)) { - rlang::abort("Internal error: Model result is not a workflow!") + cli::cli_abort("Internal error: Model result is not a workflow, but + not {.obj_type_friendly {object}.") } # Extract the parsnip model from the fitted workflow diff --git a/R/merge.R b/R/merge.R index 7c6758c1..3b27b03e 100644 --- a/R/merge.R +++ b/R/merge.R @@ -79,8 +79,7 @@ update_model <- function(grid, object, pset, step_id, nms, ...) { for (i in nms) { param_info <- pset %>% dplyr::filter(id == i & source == "model_spec") if (nrow(param_info) > 1) { - # TODO figure this out and write a better message - rlang::abort("There are too many things.") + cli::cli_abort("Cannot update; there are too many parameters.") } if (nrow(param_info) == 1) { if (param_info$component_id == "main") { @@ -111,7 +110,7 @@ update_recipe <- function(grid, object, pset, step_id, nms, ...) { merger <- function(x, y, ...) { if (!is.data.frame(y)) { - rlang::abort("The second argument should be a data frame.") + cli::cli_abort("The second argument should be a data frame.") } pset <- hardhat::extract_parameter_set_dials(x) diff --git a/R/min_grid.R b/R/min_grid.R index 406c31ff..4e8ef71a 100644 --- a/R/min_grid.R +++ b/R/min_grid.R @@ -102,7 +102,7 @@ get_fixed_args <- function(info) { get_submodel_info <- function(spec) { if (is.null(spec$engine)) { - rlang::abort("Please set the model's engine.") + cli::cli_abort("Please set the model's engine.") } param_info <- get_from_env(paste0(class(spec)[1], "_args")) %>% @@ -255,7 +255,7 @@ min_grid.linear_reg <- function(x, grid, ...) { no_penalty <- function(x, nm) { if (length(nm) == 0 || all(colnames(x) != nm)) { - rlang::abort("At least one penalty value is required for glmnet.") + cli::cli_abort("At least one penalty value is required for {.pkg glmnet}.") } invisible(NULL) } diff --git a/R/plots.R b/R/plots.R index 81ecc5b7..66d7c8c9 100644 --- a/R/plots.R +++ b/R/plots.R @@ -85,18 +85,16 @@ autoplot.tune_results <- type <- match.arg(type) has_iter <- any(names(object) == ".iter") if (!has_iter && type != "marginals") { - rlang::abort(paste0("`type = ", type, "` is only used with iterative search results.")) + cli::cli_abort("{.code type = {glue::double_quote(type)}} is only used with + iterative search results.") } pset <- .get_tune_parameters(object) if (any(is.na(pset$object))) { p_names <- pset$id[is.na(pset$object)] - msg <- - paste0( - "Some parameters do not have corresponding parameter objects ", - "and cannot be used with `autoplot()`: ", - paste0("'", p_names, "'", collapse = ", ") - ) - rlang::abort(msg) + cli::cli_abort( + "Some parameters do not have corresponding parameter objects and + cannot be used with {.fn autoplot}: {.arg {p_names}}." + ) } if (type == "parameters") { @@ -122,7 +120,7 @@ autoplot.tune_results <- #' @export autoplot.resample_results <- function(object, ...) { - rlang::abort("There is no `autoplot()` implementation for `resample_results`.") + cli::cli_abort("There is no {.fn autoplot} implementation for {.cls resample_results}.") } # ------------------------------------------------------------------------------ @@ -322,7 +320,8 @@ plot_param_vs_iter <- function(x, call = rlang::caller_env()) { param_cols <- get_param_columns(x) pset <- get_param_object(x) if (is.null(pset)) { - rlang::abort("`autoplot()` requires objects made with tune version 0.1.0 or later.") + cli::cli_abort("{.fn autoplot} requires objects made with {.pkg tune} + version 0.1.0 or later.") } # ---------------------------------------------------------------------------- @@ -378,7 +377,8 @@ plot_marginals <- function(x, metric = NULL, eval_time = NULL, call = rlang::cal param_cols <- get_param_columns(x) pset <- get_param_object(x) if (is.null(pset)) { - rlang::abort("`autoplot()` requires objects made with tune version 0.1.0 or later.") + cli::cli_abort("{.fn autoplot} requires objects made with {.pkg tune} + version 0.1.0 or later.") } # ---------------------------------------------------------------------------- @@ -408,10 +408,10 @@ plot_marginals <- function(x, metric = NULL, eval_time = NULL, call = rlang::cal num_param_cols <- param_cols[is_num] chr_param_cols <- param_cols[!is_num] if (length(chr_param_cols) > 1) { - rlang::abort("Currently cannot autoplot grids with 2+ non-numeric parameters.") + cli::cli_abort("Currently cannot autoplot grids with 2+ non-numeric parameters.") } if (length(num_param_cols) == 0) { - rlang::abort("Currently cannot autoplot grids with only non-numeric parameters.") + cli::cli_abort("Currently cannot autoplot grids with only non-numeric parameters.") } num_val <- num_val[param_cols %in% chr_param_cols] names(num_val) <- chr_param_cols @@ -521,7 +521,8 @@ plot_regular_grid <- function(x, param_cols <- get_param_columns(x) pset <- get_param_object(x) if (is.null(pset)) { - rlang::abort("`autoplot()` requires objects made with tune version 0.1.0 or later.") + cli::cli_abort("The {.fn autoplot} function requires objects made with + {.pkg tune} version 0.1.0 or later.") } grd <- dat %>% dplyr::select(all_of(param_cols)) diff --git a/R/pull.R b/R/pull.R index 63c5e6e6..89c5da2a 100644 --- a/R/pull.R +++ b/R/pull.R @@ -107,11 +107,10 @@ reduce_all_outcome_names <- function(resamples) { } if (n_unique > 1L) { - rlang::warn(paste0( - "More than one set of outcomes were used when tuning. ", - "This should never happen. ", - "Review how the outcome is specified in your model." - )) + cli::cli_warn( + "More than one set of outcomes were used when tuning. This should never + happen. Please review how the outcome is specified in your model." + ) } outcome_names <- all_outcome_names[[1L]] diff --git a/R/resample.R b/R/resample.R index 237ce4d8..44e5b4ef 100644 --- a/R/resample.R +++ b/R/resample.R @@ -60,11 +60,10 @@ fit_resamples <- function(object, ...) { #' @export fit_resamples.default <- function(object, ...) { - msg <- paste0( - "The first argument to [fit_resamples()] should be either ", - "a model or workflow." + cli::cli_abort( + "The first argument to {.fn fit_resamples} should be either a model or workflow, + not {.obj_type_friendly {object}}." ) - rlang::abort(msg) } #' @export @@ -77,10 +76,7 @@ fit_resamples.model_spec <- function(object, eval_time = NULL, control = control_resamples()) { if (rlang::is_missing(preprocessor) || !is_preprocessor(preprocessor)) { - rlang::abort(paste( - "To tune a model spec, you must preprocess", - "with a formula or recipe" - )) + cli::cli_abort(tune_pp_msg) } control <- parsnip::condense_control(control, control_resamples()) diff --git a/R/select_best.R b/R/select_best.R index b6e9bacd..ef69df29 100644 --- a/R/select_best.R +++ b/R/select_best.R @@ -32,7 +32,7 @@ #' units). See details below. #' @param eval_time A single numeric time point where dynamic event time #' metrics should be chosen (e.g., the time-dependent ROC curve, etc). The -#' values should be consistent with the values used to create `x`. The `NULL` +#' values should be consistent with the values used to create `x`. The `NULL` #' default will automatically use the first evaluation time used by `x`. #' @param call The call to be shown in errors and warnings. #' @return A tibble with columns for the parameters. [show_best()] also @@ -72,16 +72,16 @@ show_best <- function(x, ...) { #' @export #' @rdname show_best show_best.default <- function(x, ...) { - rlang::abort("No `show_best()` exists for this type of object.") + cli::cli_abort("No {.fn show_best} exists for this type of object.") } #' @export #' @rdname show_best -show_best.tune_results <- function(x, +show_best.tune_results <- function(x, ..., - metric = NULL, + metric = NULL, eval_time = NULL, - n = 5, + n = 5, call = rlang::current_env()) { rlang::check_dots_empty() @@ -114,7 +114,7 @@ select_best <- function(x, ...) { #' @export #' @rdname show_best select_best.default <- function(x, ...) { - rlang::abort("No `select_best()` exists for this type of object.") + cli::cli_abort("No {.fn select_best} exists for this type of object.") } #' @export @@ -141,7 +141,7 @@ select_by_pct_loss <- function(x, ...) { #' @export #' @rdname show_best select_by_pct_loss.default <- function(x, ...) { - rlang::abort("No `select_by_pct_loss()` exists for this type of object.") + cli::cli_abort("No {.fn select_by_pct_loss} exists for this type of object.") } #' @export @@ -207,7 +207,7 @@ select_by_one_std_err <- function(x, ...) { #' @export #' @rdname show_best select_by_one_std_err.default <- function(x, ...) { - rlang::abort("No `select_by_one_std_err()` exists for this type of object.") + cli::cli_abort("No {.fn select_by_one_std_err} exists for this type of object.") } #' @export diff --git a/R/tune_bayes.R b/R/tune_bayes.R index fd2b1e02..9603b448 100644 --- a/R/tune_bayes.R +++ b/R/tune_bayes.R @@ -182,11 +182,10 @@ tune_bayes <- function(object, ...) { #' @export tune_bayes.default <- function(object, ...) { - msg <- paste0( - "The first argument to [tune_bayes()] should be either ", - "a model or workflow." + cli::cli_abort( + "The first argument to {.fn tune_bayes} should be either a model or workflow, + not {.obj_type_friendly {object}}." ) - rlang::abort(msg) } #' @export @@ -203,10 +202,7 @@ tune_bayes.model_spec <- function(object, initial = 5, control = control_bayes()) { if (rlang::is_missing(preprocessor) || !is_preprocessor(preprocessor)) { - rlang::abort(paste( - "To tune a model spec, you must preprocess", - "with a formula or recipe" - )) + cli::cli_abort(tune_pp_msg) } # set `seed` so that calling `control_bayes()` doesn't alter RNG state (#721) @@ -840,7 +836,7 @@ check_time <- function(origin, limit) { } now_time <- proc.time()[3] if (now_time - origin >= limit * 60) { - rlang::abort(paste("The time limit of", limit, "minutes has been reached.")) + cli::cli_abort("The time limit of {limit} minute{?s} has been reached.") } invisible(NULL) } diff --git a/R/tune_grid.R b/R/tune_grid.R index b3bbc250..fe67c6a6 100644 --- a/R/tune_grid.R +++ b/R/tune_grid.R @@ -244,11 +244,10 @@ tune_grid <- function(object, ...) { #' @export tune_grid.default <- function(object, ...) { - msg <- paste0( - "The first argument to [tune_grid()] should be either ", - "a model or workflow." + cli::cli_abort( + "The first argument to {.fn tune_grid} should be either a model or workflow, + not {.obj_type_friendly {object}}." ) - rlang::abort(msg) } #' @export @@ -257,10 +256,7 @@ tune_grid.model_spec <- function(object, preprocessor, resamples, ..., param_info = NULL, grid = 10, metrics = NULL, eval_time = NULL, control = control_grid()) { if (rlang::is_missing(preprocessor) || !is_preprocessor(preprocessor)) { - rlang::abort(paste( - "To tune a model spec, you must preprocess", - "with a formula or recipe" - )) + cli::cli_abort(tune_pp_msg) } control <- parsnip::condense_control(control, control_grid()) @@ -298,7 +294,7 @@ tune_grid.workflow <- function(object, resamples, ..., param_info = NULL, # Disallow `NULL` grids in `tune_grid()`, as this is the special signal # used when no tuning is required if (is.null(grid)) { - rlang::abort(grid_msg) + cli::cli_abort(grid_msg) } res <- @@ -364,7 +360,10 @@ tune_grid_workflow <- function(workflow, ) if (is_cataclysmic(resamples)) { - rlang::warn("All models failed. Run `show_notes(.Last.tune.result)` for more information.") + cli::cli_warn( + "All models failed. Run {.code show_notes(.Last.tune.result)} for more + information." + ) } outcomes <- reduce_all_outcome_names(resamples) diff --git a/R/tune_results.R b/R/tune_results.R index da0bb114..caa74973 100644 --- a/R/tune_results.R +++ b/R/tune_results.R @@ -126,13 +126,15 @@ is_tune_results <- function(x) { peek_tune_results_outcomes <- function(x) { if (!is_tune_results(x)) { - rlang::abort("Internal error: `outcomes` can only be extracted from 'tune_results'.") + cli::cli_abort("Internal error: {.arg outcomes} can only be extracted from + {.cls tune_results}.") } out <- attr(x, "outcomes", exact = TRUE) if (is.null(out)) { - rlang::abort("'tune_results' object doesn't have an 'outcomes' attribute.") + cli::cli_abort("The object of type {.cls tune_results} doesn't have an + {.code outcomes} attribute.") } out diff --git a/R/utils.R b/R/utils.R index 28404c40..c94e70b2 100644 --- a/R/utils.R +++ b/R/utils.R @@ -8,9 +8,24 @@ empty_ellipses <- function(...) { dots <- rlang::enquos(...) if (length(dots) > 0) { - msg <- "The `...` are not used in this function but one or more objects were passed: " - msg <- paste0(msg, paste0("'", names(dots), "'", collapse = ", ")) - rlang::warn(msg) + nms <- names(dots) + no_name <- nms == "" + if (!any(no_name)) { + cli::cli_warn( + "The {.code ...} are not used in this function but {length(dots)} + object{?s} {?was/were} passed: {.val {names(dots)}}" + ) + } else if (all(no_name)) { + cli::cli_warn( + "The {.code ...} are not used in this function but {length(dots)} + unnamed object{?s} {?was/were} passed." + ) + } else { + cli::cli_warn( + "The {.code ...} are not used in this function but {length(dots)} + object{?s} {?was/were} passed." + ) + } } invisible(NULL) } diff --git a/tests/testthat/_snaps/acquisition.md b/tests/testthat/_snaps/acquisition.md index e476ac2f..15616a6a 100644 --- a/tests/testthat/_snaps/acquisition.md +++ b/tests/testthat/_snaps/acquisition.md @@ -12,7 +12,7 @@ conf_bound(function() 1) Condition Error in `conf_bound()`: - ! The `trade_off` function should have at least one argument. + ! The `trade_off()` function should have at least one argument. --- @@ -36,7 +36,7 @@ prob_improve(function() 1) Condition Error in `prob_improve()`: - ! The `trade_off` function should have at least one argument. + ! The `trade_off()` function should have at least one argument. --- @@ -76,7 +76,7 @@ exp_improve(function() 2) Condition Error in `exp_improve()`: - ! The `trade_off` function should have at least one argument. + ! The `trade_off()` function should have at least one argument. --- diff --git a/tests/testthat/_snaps/augment.md b/tests/testthat/_snaps/augment.md index 36bf4eb2..266bd2f4 100644 --- a/tests/testthat/_snaps/augment.md +++ b/tests/testthat/_snaps/augment.md @@ -22,7 +22,7 @@ augment(fit_1, parameters = list(cost = 3)) Condition Error in `augment()`: - ! 'parameters' should be a single row data frame + ! `parameters` should be a single row data frame. --- @@ -30,7 +30,7 @@ augment(fit_1, parameters = data.frame(cost = 3:4)) Condition Error in `augment()`: - ! 'parameters' should be a single row data frame + ! `parameters` should be a single row data frame. --- diff --git a/tests/testthat/_snaps/autoplot.md b/tests/testthat/_snaps/autoplot.md index 76ce0bf4..4994fe66 100644 --- a/tests/testthat/_snaps/autoplot.md +++ b/tests/testthat/_snaps/autoplot.md @@ -4,7 +4,7 @@ autoplot(knn_results, type = "performance") Condition Error in `autoplot()`: - ! `type = performance` is only used with iterative search results. + ! `type = "performance"` is only used with iterative search results. --- @@ -12,7 +12,7 @@ autoplot(knn_results, type = "parameters") Condition Error in `autoplot()`: - ! `type = parameters` is only used with iterative search results. + ! `type = "parameters"` is only used with iterative search results. # coord_obs_pred diff --git a/tests/testthat/_snaps/bayes.md b/tests/testthat/_snaps/bayes.md index c9fefcdc..700566fe 100644 --- a/tests/testthat/_snaps/bayes.md +++ b/tests/testthat/_snaps/bayes.md @@ -432,7 +432,7 @@ param_info = extract_parameter_set_dials(rec_tune_1), iter = iter1, initial = iter2) Condition Error in `tune_bayes()`: - ! The first argument to [tune_bayes()] should be either a model or workflow. + ! The first argument to `tune_bayes()` should be either a model or workflow, not a object. # argument order gives an error for formula @@ -441,7 +441,7 @@ param_info = extract_parameter_set_dials(svm_mod), initial = iter1, iter = iter2) Condition Error in `tune_bayes()`: - ! The first argument to [tune_bayes()] should be either a model or workflow. + ! The first argument to `tune_bayes()` should be either a model or workflow, not a object. # retain extra attributes and saved GP candidates @@ -465,7 +465,7 @@ tune:::check_bayes_initial_size(5, 3, FALSE) Message ! There are 5 tuning parameters and 3 grid points were requested. - * There are more tuning parameters than there are initial points. This is + * There are as many tuning parameters as there are initial points. This is likely to cause numerical issues in the first few search iterations. --- @@ -474,7 +474,7 @@ tune:::check_bayes_initial_size(5, 3, TRUE) Message ! There are 5 tuning parameters and 3 grid points were requested. - * There are more tuning parameters than there are initial points. This is + * There are as many tuning parameters as there are initial points. This is likely to cause numerical issues in the first few search iterations. * With racing, only completely resampled parameters are used. @@ -492,28 +492,28 @@ Code tune:::check_bayes_initial_size(5, 1, FALSE) Condition - Error: + Error in `tune:::check_bayes_initial_size()`: ! There are 5 tuning parameters and 1 grid point was requested. - * The GP model requires 2+ initial points. For best performance, supply more initial points than there are tuning parameters. + i The GP model requires 2+ initial points. For best performance, supply more initial points than there are tuning parameters. --- Code tune:::check_bayes_initial_size(5, 1, TRUE) Condition - Error: + Error in `tune:::check_bayes_initial_size()`: ! There are 5 tuning parameters and 1 grid point was requested. - * The GP model requires 2+ initial points. For best performance, supply more initial points than there are tuning parameters. - * With racing, only completely resampled parameters are used. + i The GP model requires 2+ initial points. For best performance, supply more initial points than there are tuning parameters. + i With racing, only completely resampled parameters are used. --- Code tune:::check_bayes_initial_size(1, 1, FALSE) Condition - Error: + Error in `tune:::check_bayes_initial_size()`: ! There is 1 tuning parameter and 1 grid point was requested. - * The GP model requires 2+ initial points. For best performance, supply more initial points than there are tuning parameters. + i The GP model requires 2+ initial points. For best performance, supply more initial points than there are tuning parameters. # missing performance values diff --git a/tests/testthat/_snaps/case-weights.md b/tests/testthat/_snaps/case-weights.md index 3fc5881e..616b4d68 100644 --- a/tests/testthat/_snaps/case-weights.md +++ b/tests/testthat/_snaps/case-weights.md @@ -4,9 +4,9 @@ .use_case_weights_with_yardstick(1) Condition Error in `.use_case_weights_with_yardstick()`: - ! Unknown case weights object with class . + ! An object with was expected, not a number. i Define a `.use_case_weights_with_yardstick()` method for this type to declare whether or not these case weights should be passed on to yardstick. - i See `?.use_case_weights_with_yardstick` for more information. + i See `?.use_case_weights_with_yardstick()` for more information. # `extract_case_weights()` errors if `col` doesn't exist diff --git a/tests/testthat/_snaps/censored-reg.md b/tests/testthat/_snaps/censored-reg.md index b6f546da..53a43be3 100644 --- a/tests/testthat/_snaps/censored-reg.md +++ b/tests/testthat/_snaps/censored-reg.md @@ -23,7 +23,8 @@ Warning in `tune_grid()`: `eval_time` is only used for models with mode "censored regression". Warning: - No tuning parameters have been detected, performance will be evaluated using the resamples with no tuning. Did you want to [tune()] parameters? + No tuning parameters have been detected, performance will be evaluated using the resamples with no tuning. + Did you want to assign any parameters with a value of `tune()`? Output # Tuning results # 10-fold cross-validation using stratification diff --git a/tests/testthat/_snaps/checks.md b/tests/testthat/_snaps/checks.md index d98ea891..2eea7eb3 100644 --- a/tests/testthat/_snaps/checks.md +++ b/tests/testthat/_snaps/checks.md @@ -58,7 +58,7 @@ tune:::check_grid(grid, workflow) Condition Error in `tune:::check_grid()`: - ! The provided `grid` has the following parameter columns that have not been marked for tuning by `tune()`: 'other1', 'other2'. + ! The provided grid has 2 parameter columns (`other1` and `other2`) that have not been marked for tuning by `tune()`. # Missing required `grid` columns are caught @@ -66,7 +66,7 @@ tune:::check_grid(grid, workflow) Condition Error in `tune:::check_grid()`: - ! The provided `grid` is missing the following parameter columns that have been marked for tuning by `tune()`: 'deg_free'. + ! The provided grid is missing the following 1 parameter column that has been marked for tuning by `tune()`: "deg_free". # workflow objects @@ -74,7 +74,7 @@ tune:::check_workflow(x = wflow_2, check_dials = TRUE) Condition Error in `tune:::check_workflow()`: - ! The workflow has arguments whose ranges are not finalized: 'mtry' + ! The workflow has arguments whose ranges are not finalized: "mtry". --- @@ -132,7 +132,7 @@ tune:::check_metrics(yardstick::rmse, chi_wflow) Condition Error in `tune:::check_metrics()`: - ! The `metrics` argument should be the results of [yardstick::metric_set()]. + ! The `metrics` argument should be the results of `yardstick::metric_set()`. # metrics must match the parsnip engine @@ -302,7 +302,7 @@ yardstick::rsq), ctrl = control_bayes()) Condition Error in `tune:::check_initial()`: - ! `initial` should be a positive integer or the results of [tune_grid()] + ! `initial` should be a positive integer or the results of `tune_grid()` # check parameter finalization @@ -310,21 +310,21 @@ expect_no_error(p1 <- tune:::check_parameters(w1, data = mtcars, grid_names = character( 0))) Message - i Creating pre-processing data to finalize unknown parameter: mtry + i Creating pre-processing data to finalize 1 unknown parameter: "mtry" --- Code expect_no_error(p2 <- tune:::check_parameters(w2, data = mtcars)) Message - i Creating pre-processing data to finalize unknown parameter: mtry + i Creating pre-processing data to finalize 1 unknown parameter: "mtry" --- Code expect_no_error(p3_a <- tune:::check_parameters(w3, data = mtcars)) Message - i Creating pre-processing data to finalize unknown parameter: mtry + i Creating pre-processing data to finalize 1 unknown parameter: "mtry" --- @@ -332,5 +332,6 @@ tune:::check_parameters(w4, data = mtcars) Condition Error in `tune:::check_parameters()`: - ! Some model parameters require finalization but there are recipe parameters that require tuning. Please use `extract_parameter_set_dials()` to set parameter ranges manually and supply the output to the `param_info` argument. + ! Some model parameters require finalization but there are recipe parameters that require tuning. + i Please use `extract_parameter_set_dials()` to set parameter ranges manually and supply the output to the `param_info` argument. diff --git a/tests/testthat/_snaps/collect.md b/tests/testthat/_snaps/collect.md index 2976215c..a8e051db 100644 --- a/tests/testthat/_snaps/collect.md +++ b/tests/testthat/_snaps/collect.md @@ -4,7 +4,7 @@ collect_predictions(lm_splines %>% dplyr::select(-.predictions)) Condition Error in `collect_predictions()`: - ! The `.predictions` column does not exist. Refit with the control argument `save_pred = TRUE` to save predictions. + ! The .predictions column does not exist. Please refit with the control argument `save_pred = TRUE` to save predictions. # `collect_predictions()` errors informatively applied to unsupported class @@ -20,7 +20,7 @@ collect_predictions(svm_tune, parameters = tibble(wrong = "value")) Condition Error in `filter_predictions()`: - ! `parameters` should only have columns: 'cost value' + ! `parameters` should only have columns: "cost value". # collecting notes - fit_resamples diff --git a/tests/testthat/_snaps/compute_metrics.md b/tests/testthat/_snaps/compute_metrics.md index de2bac52..3560f458 100644 --- a/tests/testthat/_snaps/compute_metrics.md +++ b/tests/testthat/_snaps/compute_metrics.md @@ -30,7 +30,7 @@ compute_metrics("boop", metric_set(rsq)) Condition Error in `compute_metrics()`: - ! No `compute_metrics()` method exists for this type of object. + ! No `compute_metrics()` method exists for a string. --- diff --git a/tests/testthat/_snaps/conf-mat-resampled.md b/tests/testthat/_snaps/conf-mat-resampled.md index 1ac63c0e..9b194e86 100644 --- a/tests/testthat/_snaps/conf-mat-resampled.md +++ b/tests/testthat/_snaps/conf-mat-resampled.md @@ -4,7 +4,7 @@ conf_mat_resampled(svm_results) Condition Error in `conf_mat_resampled()`: - ! It looks like there are 5 tuning parameter combination(s) in the data. Please use the `parameters` argument to select one combination of parameters. + ! It looks like there are 5 tuning parameter combination in the data. Please use the `parameters` argument to select one combination of parameters. --- @@ -28,7 +28,7 @@ conf_mat_resampled(tibble::as_tibble(svm_results)) Condition Error in `conf_mat_resampled()`: - ! The first argument needs to be an object with class 'tune_results'. + ! The first argument needs to be object, not a data frame. --- diff --git a/tests/testthat/_snaps/engine-parameters.md b/tests/testthat/_snaps/engine-parameters.md index 76194a9f..09f88212 100644 --- a/tests/testthat/_snaps/engine-parameters.md +++ b/tests/testthat/_snaps/engine-parameters.md @@ -4,7 +4,7 @@ rf_tune <- rf_mod %>% tune_grid(mpg ~ ., resamples = rs, grid = 3) Condition Error in `check_param_objects()`: - ! The workflow has arguments to be tuned that are missing some parameter objects: 'corr.bias' + ! The workflow has arguments to be tuned that are missing some parameter objects: "corr.bias" --- @@ -12,7 +12,7 @@ p <- autoplot(rf_tune) Condition Error in `autoplot()`: - ! Some parameters do not have corresponding parameter objects and cannot be used with `autoplot()`: 'corr.bias' + ! Some parameters do not have corresponding parameter objects and cannot be used with `autoplot()`: `corr.bias`. --- @@ -20,5 +20,5 @@ rf_search <- rf_mod %>% tune_bayes(mpg ~ ., resamples = rs) Condition Error in `check_param_objects()`: - ! The workflow has arguments to be tuned that are missing some parameter objects: 'corr.bias' + ! The workflow has arguments to be tuned that are missing some parameter objects: "corr.bias" diff --git a/tests/testthat/_snaps/filter-parameters.md b/tests/testthat/_snaps/filter-parameters.md index 4001ac96..422b88ea 100644 --- a/tests/testthat/_snaps/filter-parameters.md +++ b/tests/testthat/_snaps/filter-parameters.md @@ -5,8 +5,7 @@ `%^*#` = 1)) Condition Error in `filter_parameters()`: - ! collect_metrics should have class 'tune_results'. - * svm_reg_results should have class 'tune_results'. + ! `collect_metrics(svm_reg_results)` should have class ; a tibble was passed. --- @@ -14,7 +13,7 @@ filter_parameters(svm_reg_results, parameters = tibble::tibble(soup = 1)) Condition Error in `filter_by_join()`: - ! There are no columns in 'parameters' that match with svm_reg_results + ! There are no columns in `parameters` that match with "svm_reg_results". --- diff --git a/tests/testthat/_snaps/finalization.md b/tests/testthat/_snaps/finalization.md index 52b78da8..38b240ac 100644 --- a/tests/testthat/_snaps/finalization.md +++ b/tests/testthat/_snaps/finalization.md @@ -4,5 +4,6 @@ mod_1 %>% tune_grid(rec_1, resamples = rs, grid = 3) Condition Error in `check_parameters()`: - ! Some model parameters require finalization but there are recipe parameters that require tuning. Please use `extract_parameter_set_dials()` to set parameter ranges manually and supply the output to the `param_info` argument. + ! Some model parameters require finalization but there are recipe parameters that require tuning. + i Please use `extract_parameter_set_dials()` to set parameter ranges manually and supply the output to the `param_info` argument. diff --git a/tests/testthat/_snaps/fit_best.md b/tests/testthat/_snaps/fit_best.md index 3e8e951e..d9daaf20 100644 --- a/tests/testthat/_snaps/fit_best.md +++ b/tests/testthat/_snaps/fit_best.md @@ -42,11 +42,11 @@ --- - There is no `fit_best()` method for an object with class `integer`. + No `fit_best()` exists for an integer. --- - There is no `fit_best()` method for an object with classes `tbl_df`, `tbl`, and `data.frame`. + No `fit_best()` exists for a tibble. --- diff --git a/tests/testthat/_snaps/grid.md b/tests/testthat/_snaps/grid.md index a975cfb4..7369ce99 100644 --- a/tests/testthat/_snaps/grid.md +++ b/tests/testthat/_snaps/grid.md @@ -43,7 +43,7 @@ mtcars, v = 2)) Condition Error in `tune_grid()`: - ! The first argument to [tune_grid()] should be either a model or workflow. + ! The first argument to `tune_grid()` should be either a model or workflow, not a object. # argument order gives errors for formula @@ -51,7 +51,7 @@ tune_grid(mpg ~ ., helper_objects$lm_mod, rsample::vfold_cv(mtcars, v = 2)) Condition Error in `tune_grid()`: - ! The first argument to [tune_grid()] should be either a model or workflow. + ! The first argument to `tune_grid()` should be either a model or workflow, not a object. # ellipses with tune_grid @@ -59,7 +59,7 @@ tune_grid(wflow, resamples = folds, grid = 3, something = "wrong") Condition Warning: - The `...` are not used in this function but one or more objects were passed: 'something' + The `...` are not used in this function but 1 object was passed: "something" Output # Tuning results # 10-fold cross-validation diff --git a/tests/testthat/_snaps/last-fit.md b/tests/testthat/_snaps/last-fit.md index d49fc24d..6ea96647 100644 --- a/tests/testthat/_snaps/last-fit.md +++ b/tests/testthat/_snaps/last-fit.md @@ -21,7 +21,7 @@ linear_reg() %>% set_engine("lm") %>% last_fit(f, split, something = "wrong") Condition Warning: - The `...` are not used in this function but one or more objects were passed: 'something' + The `...` are not used in this function but 1 object was passed: "something" Output # Resampling results # Manual resampling @@ -36,7 +36,7 @@ last_fit(rec, lin_mod, split) Condition Error in `last_fit()`: - ! The first argument to [last_fit()] should be either a model or workflow. + ! The first argument to `last_fit()` should be either a model or workflow, not a object. --- @@ -44,20 +44,20 @@ last_fit(f, lin_mod, split) Condition Error in `last_fit()`: - ! The first argument to [last_fit()] should be either a model or workflow. + ! The first argument to `last_fit()` should be either a model or workflow, not a object. # `last_fit()` when objects need tuning - 2 arguments have been tagged for tuning in these components: model_spec and recipe. - Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. + 2 arguments have been tagged for tuning in these components: model_spec and recipe. + i Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. --- - 1 argument has been tagged for tuning in this component: model_spec. - Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. + 1 argument has been tagged for tuning in this component: model_spec. + i Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. --- - 1 argument has been tagged for tuning in this component: recipe. - Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. + 1 argument has been tagged for tuning in this component: recipe. + i Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. diff --git a/tests/testthat/_snaps/misc.md b/tests/testthat/_snaps/misc.md index 0ab3b02f..40edfd02 100644 --- a/tests/testthat/_snaps/misc.md +++ b/tests/testthat/_snaps/misc.md @@ -4,5 +4,5 @@ tune:::empty_ellipses(a = 1) Condition Warning: - The `...` are not used in this function but one or more objects were passed: 'a' + The `...` are not used in this function but 1 object was passed: "a" diff --git a/tests/testthat/_snaps/resample.md b/tests/testthat/_snaps/resample.md index 9fc0e154..835082c9 100644 --- a/tests/testthat/_snaps/resample.md +++ b/tests/testthat/_snaps/resample.md @@ -74,7 +74,8 @@ result <- tune_grid(lin_mod, mpg ~ ., folds) Condition Warning: - No tuning parameters have been detected, performance will be evaluated using the resamples with no tuning. Did you want to [tune()] parameters? + No tuning parameters have been detected, performance will be evaluated using the resamples with no tuning. + Did you want to assign any parameters with a value of `tune()`? # `tune_grid()` falls back to `fit_resamples()` - workflow variables @@ -82,7 +83,8 @@ result <- tune_grid(wf, folds) Condition Warning: - No tuning parameters have been detected, performance will be evaluated using the resamples with no tuning. Did you want to [tune()] parameters? + No tuning parameters have been detected, performance will be evaluated using the resamples with no tuning. + Did you want to assign any parameters with a value of `tune()`? # `tune_grid()` ignores `grid` if there are no tuning parameters @@ -90,7 +92,8 @@ result <- lin_mod %>% tune_grid(mpg ~ ., grid = data.frame(x = 1), folds) Condition Warning: - No tuning parameters have been detected, performance will be evaluated using the resamples with no tuning. Did you want to [tune()] parameters? + No tuning parameters have been detected, performance will be evaluated using the resamples with no tuning. + Did you want to assign any parameters with a value of `tune()`? # cannot autoplot `fit_resamples()` results @@ -98,7 +101,7 @@ autoplot(result) Condition Error in `autoplot()`: - ! There is no `autoplot()` implementation for `resample_results`. + ! There is no `autoplot()` implementation for . # ellipses with fit_resamples @@ -106,7 +109,7 @@ lin_mod %>% fit_resamples(mpg ~ ., folds, something = "wrong") Condition Warning: - The `...` are not used in this function but one or more objects were passed: 'something' + The `...` are not used in this function but 1 object was passed: "something" Output # Resampling results # 2-fold cross-validation @@ -122,7 +125,7 @@ fit_resamples(rec, lin_mod, folds) Condition Error in `fit_resamples()`: - ! The first argument to [fit_resamples()] should be either a model or workflow. + ! The first argument to `fit_resamples()` should be either a model or workflow, not a object. --- @@ -130,7 +133,7 @@ fit_resamples(mpg ~ ., lin_mod, folds) Condition Error in `fit_resamples()`: - ! The first argument to [fit_resamples()] should be either a model or workflow. + ! The first argument to `fit_resamples()` should be either a model or workflow, not a object. # retain extra attributes @@ -152,16 +155,16 @@ # `fit_resamples()` when objects need tuning - 2 arguments have been tagged for tuning in these components: model_spec and recipe. - Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. + 2 arguments have been tagged for tuning in these components: model_spec and recipe. + i Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. --- - 1 argument has been tagged for tuning in this component: model_spec. - Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. + 1 argument has been tagged for tuning in this component: model_spec. + i Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. --- - 1 argument has been tagged for tuning in this component: recipe. - Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. + 1 argument has been tagged for tuning in this component: recipe. + i Please use one of the tuning functions (e.g. `tune_grid()`) to optimize them. diff --git a/tests/testthat/_snaps/utils.md b/tests/testthat/_snaps/utils.md new file mode 100644 index 00000000..921251a3 --- /dev/null +++ b/tests/testthat/_snaps/utils.md @@ -0,0 +1,40 @@ +# check for no arguments pass to ... + + Code + empty_ellipses(a = 5) + Condition + Warning: + The `...` are not used in this function but 1 object was passed: "a" + +--- + + Code + empty_ellipses(a = 5, b = 1) + Condition + Warning: + The `...` are not used in this function but 2 objects were passed: "a" and "b" + +--- + + Code + empty_ellipses(5) + Condition + Warning: + The `...` are not used in this function but 1 unnamed object was passed. + +--- + + Code + empty_ellipses(1, 5) + Condition + Warning: + The `...` are not used in this function but 2 unnamed objects were passed. + +--- + + Code + empty_ellipses(1, second = 2) + Condition + Warning: + The `...` are not used in this function but 2 objects were passed. + diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R new file mode 100644 index 00000000..17e00c74 --- /dev/null +++ b/tests/testthat/test-utils.R @@ -0,0 +1,18 @@ +test_that("check for no arguments pass to ...", { + + expect_snapshot( + empty_ellipses(a = 5) + ) + expect_snapshot( + empty_ellipses(a = 5, b = 1) + ) + expect_snapshot( + empty_ellipses(5) + ) + expect_snapshot( + empty_ellipses(1, 5) + ) + expect_snapshot( + empty_ellipses(1, second = 2) + ) +})