Skip to content
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

Merged
merged 16 commits into from
Nov 21, 2024
12 changes: 6 additions & 6 deletions R/acquisition.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
#' @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"

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.")
}
Expand Down Expand Up @@ -107,15 +107,15 @@ 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"

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.")
}
Expand Down Expand Up @@ -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.")
topepo marked this conversation as resolved.
Show resolved Hide resolved
}
lab <- paste(lab, "with variable kappa values.")
}
Expand Down
10 changes: 4 additions & 6 deletions R/augment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}

Expand Down Expand Up @@ -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."
)
}

Expand Down
31 changes: 16 additions & 15 deletions R/case_weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
topepo marked this conversation as resolved.
Show resolved Hide resolved
"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
Expand All @@ -55,18 +57,18 @@
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)

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
Expand Down Expand Up @@ -96,12 +98,11 @@
)

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

Check warning on line 104 in R/case_weights.R

View check run for this annotation

Codecov / codecov/patch

R/case_weights.R#L101-L104

Added lines #L101 - L104 were not covered by tests
)

rlang::abort(message, call = call)
}

loc
Expand Down
Loading