Skip to content

Commit

Permalink
conversion of warnings and errors to cli (#954)
Browse files Browse the repository at this point in the history
* acquisition changes

* augment and case weights

* changes for the checks.R file

* remaining cli updates

* convert warnings

* updated snapshots

* Apply suggestions from code review

Co-authored-by: Simon P. Couch <[email protected]>

* expand messages for empty_ellipses

* update snapshots

* Update R/checks.R

Co-authored-by: Simon P. Couch <[email protected]>

* update case weight message

* revert change; figure out later

* more msg updates

---------

Co-authored-by: Simon P. Couch <[email protected]>
  • Loading branch information
topepo and simonpcouch authored Nov 21, 2024
1 parent fec77ef commit f6772f4
Show file tree
Hide file tree
Showing 49 changed files with 446 additions and 396 deletions.
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.")
}
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(
"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 @@ 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)

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 @@ 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
Expand Down
Loading

0 comments on commit f6772f4

Please sign in to comment.