-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
conversion of warnings and errors to cli #954
base: main
Are you sure you want to change the base?
Conversation
@@ -372,37 +364,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}.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous messages has [pkg:fun()]
format. Do we want to move to that? I don't think that they were clickable.
"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}}.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using obj_type_friendly
a lot in these messages.
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}}." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I standardized on this message for all of the main default methods.
@@ -117,16 +116,17 @@ last_fit.model_fit <- function(object, ...) { | |||
)) | |||
} | |||
|
|||
tune_pp_msg <- "To tune a model specification, you must preprocess with a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More standardization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done!
@@ -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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe time to retire this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
@@ -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. ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was weirdly aggro. Ahh, me in July 2021. I blame the 'rona.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hahahaha i feel like this is the most likely error i see when i introduce bugs in the grid code paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this PR is going to make tidymodels feel much more modern/slick for many users. Heck yeah!
} | ||
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.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cli::cli_abort("The {.fn trade_off} function should have at least one argument.") | |
cli::cli_abort("The {.fn kappa} function should have at least one argument.") |
I think this error should have referenced this argument all along?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing that it's maybe ambiguous whether to use .fn
or .arg
in these—fine with me to go the route you've chosen.
cli::format_inline("Unknown case weights object contains | ||
{.obj_type_friendly {x}} instead of an object with a | ||
case weight class."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cli::format_inline("Unknown case weights object contains | |
{.obj_type_friendly {x}} instead of an object with a | |
case weight class."), | |
"Unknown case weights object contains {.obj_type_friendly {x}} instead | |
of an object with a case weight class.", |
paste0("Unknown case weights object with class <", class(x)[[1]], ">. "), | ||
cli::format_inline("Unknown case weights object contains | ||
{.obj_type_friendly {x}} instead of an object with a | ||
case weight class."), | ||
i = paste0( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This paste0()
can be removed and made a string with a(n implicit) newline
i = paste0( | ||
"Define a `.use_case_weights_with_yardstick()` method for this type to ", | ||
"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 yardstick." | ||
), | ||
i = "See `?.use_case_weights_with_yardstick` for more information." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i = "See `?.use_case_weights_with_yardstick` for more information." | |
i = "See {.help .use_case_weights_with_yardstick} for more information." |
"The `.predictions` column does not exist. ", | ||
"Refit with the control argument `save_pred = TRUE` to save predictions." | ||
cli::cli_abort( | ||
"The {.code .predictions} column does not exist. Please refit with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The {.code .predictions} column does not exist. Please refit with the | |
"The {.field .predictions} column does not exist. Please refit with the |
following Emil's lead here
} | ||
|
||
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} object doesn't have an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cli::cli_abort("The object of type {.cls tune_results} object doesn't have an | |
cli::cli_abort("The object of type {.cls tune_results} doesn't have an |
cli::cli_warn( | ||
"The {.code ...} are not used in this function but {length(dots)} | ||
object{?s} {?was/were} passed: {.val {names(dots)}}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref #829
! 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. | ||
i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty i = ""
, it seems
@@ -4,7 +4,7 @@ | |||
.use_case_weights_with_yardstick(1) | |||
Condition | |||
Error in `.use_case_weights_with_yardstick()`: | |||
! Unknown case weights object with class <numeric>. | |||
! Unknown case weights object contains a number instead of an object with a case weight class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if this can be more succinct / plainly written
num_unk <- length(unk_names) | ||
msg <- cli::format_inline( | ||
"Creating pre-processing data to finalize {num_unk} unknown parameter{?s}: {.val {unk_names}}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
num_unk <- length(unk_names) | |
msg <- cli::format_inline( | |
"Creating pre-processing data to finalize {num_unk} unknown parameter{?s}: {.val {unk_names}}" | |
) | |
msg <- | |
"Creating pre-processing data to finalize unknown parameter{?s} {.val {unk_names}}." |
Since this is a very common message I am going to be fussy about my enum-after-parens pet peeve--feel free to ignore that part of this suggestion if you please🤪
pal was a godsend here 💯