Skip to content

Commit

Permalink
transition to cli (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch authored Aug 28, 2024
1 parent 146bd6b commit 149f601
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
18 changes: 9 additions & 9 deletions R/nearest_neighbor_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ set_pred(
# model mode
pre = function(x, object) {
if (object$fit$response != "continuous") {
rlang::abort(
glue::glue("`kknn` model does not appear to use numeric predictions.",
" Was the model fit with a continuous response variable?")
cli::cli_abort(
c("`kknn` model does not appear to use numeric predictions.",
"i" = "Was the model fit with a continuous response variable?")
)
}
x
Expand Down Expand Up @@ -136,9 +136,9 @@ set_pred(
value = list(
pre = function(x, object) {
if (!(object$fit$response %in% c("ordinal", "nominal"))) {
rlang::abort(
glue::glue("`kknn` model does not appear to use class predictions.",
" Was the model fit with a factor response variable?")
cli::cli_abort(
c("`kknn` model does not appear to use class predictions.",
"i" = "Was the model fit with a factor response variable?")
)
}
x
Expand All @@ -162,9 +162,9 @@ set_pred(
value = list(
pre = function(x, object) {
if (!(object$fit$response %in% c("ordinal", "nominal"))) {
rlang::abort(
glue::glue("`kknn` model does not appear to use class predictions.",
" Was the model fit with a factor response variable?")
cli::cli_abort(
c("`kknn` model does not appear to use class predictions.",
"i" = "Was the model fit with a factor response variable?")
)
}
x
Expand Down
13 changes: 9 additions & 4 deletions R/rand_forest.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ translate.rand_forest <- function(x, engine = x$engine, ...) {

if (x$engine == "spark") {
if (x$mode == "unknown") {
rlang::abort(
glue::glue("For spark random forests models, the mode cannot ",
"be 'unknown' if the specification is to be translated.")
cli::cli_abort(
"For spark random forest models, the mode cannot
be {.val unknown} if the specification is to be translated."
)
} else {
arg_vals$type <- x$mode
Expand All @@ -121,7 +121,12 @@ translate.rand_forest <- function(x, engine = x$engine, ...) {

if (any(names(arg_vals) == "importance")) {
if (isTRUE(is.logical(quo_get_expr(arg_vals$importance)))) {
rlang::abort("`importance` should be a character value. See ?ranger::ranger.")
cli::cli_abort(
c(
"{.arg importance} should be a character value.",
"i" = "See ?ranger::ranger."
)
)
}
}
# unless otherwise specified, classification models are probability forests
Expand Down
16 changes: 7 additions & 9 deletions R/rand_forest_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ ranger_confint <- function(object, new_data, ...) {
if (object$fit$forest$treetype == "Probability estimation") {
res <- ranger_class_confint(object, new_data, ...)
} else {
rlang::abort(
glue::glue(
"Cannot compute confidence intervals for a ranger forest ",
"of type {object$fit$forest$treetype}."
)
cli::cli_abort(
"Cannot compute confidence intervals for a ranger forest
of type {.val {object$fit$forest$treetype}}."
)
}
}
Expand Down Expand Up @@ -204,10 +202,10 @@ set_pred(
value = list(
pre = function(x, object) {
if (object$fit$forest$treetype != "Probability estimation")
rlang::abort(
glue::glue(
"`ranger` model does not appear to use class probabilities. Was ",
"the model fit with `probability = TRUE`?"
cli::cli_abort(
c(
"`ranger` model does not appear to use class probabilities.",
"i" = "Was the model fit with `probability = TRUE`?"
)
)
x
Expand Down
7 changes: 3 additions & 4 deletions R/svm_linear.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ translate.svm_linear <- function(x, engine = x$engine, ...) {
arg_vals$svr_eps <- 0.1
if (!is_null(liblinear_type))
if(!liblinear_type %in% 11:13)
rlang::abort(
paste0("The LiblineaR engine argument of `type` = ",
liblinear_type,
" does not correspond to an SVM regression model.")
cli::cli_abort(
"The LiblineaR engine argument {.code type = {liblinear_type}}
does not correspond to an SVM regression model."
)
} else if (x$mode == "classification") {
if (!is_null(liblinear_type))
Expand Down
8 changes: 5 additions & 3 deletions R/svm_rbf_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,11 @@ set_pred(
value = list(
pre = function(x, object) {
if (!object$fit$predict.prob) {
rlang::abort(
paste0("`svm` model does not appear to use class probabilities. Was ",
"the model fit with `predict.prob = TRUE`?")
cli::cli_abort(
c(
"The model does not appear to use class probabilities.",
"i" = "Was the model fit with {.code predict.prob = TRUE}?"
)
)
}
x
Expand Down

0 comments on commit 149f601

Please sign in to comment.