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

transition to cli from rlang #1160

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading