Skip to content

Commit 149f601

Browse files
authored
transition to cli (#1160)
1 parent 146bd6b commit 149f601

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

R/nearest_neighbor_data.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ set_pred(
9393
# model mode
9494
pre = function(x, object) {
9595
if (object$fit$response != "continuous") {
96-
rlang::abort(
97-
glue::glue("`kknn` model does not appear to use numeric predictions.",
98-
" Was the model fit with a continuous response variable?")
96+
cli::cli_abort(
97+
c("`kknn` model does not appear to use numeric predictions.",
98+
"i" = "Was the model fit with a continuous response variable?")
9999
)
100100
}
101101
x
@@ -136,9 +136,9 @@ set_pred(
136136
value = list(
137137
pre = function(x, object) {
138138
if (!(object$fit$response %in% c("ordinal", "nominal"))) {
139-
rlang::abort(
140-
glue::glue("`kknn` model does not appear to use class predictions.",
141-
" Was the model fit with a factor response variable?")
139+
cli::cli_abort(
140+
c("`kknn` model does not appear to use class predictions.",
141+
"i" = "Was the model fit with a factor response variable?")
142142
)
143143
}
144144
x
@@ -162,9 +162,9 @@ set_pred(
162162
value = list(
163163
pre = function(x, object) {
164164
if (!(object$fit$response %in% c("ordinal", "nominal"))) {
165-
rlang::abort(
166-
glue::glue("`kknn` model does not appear to use class predictions.",
167-
" Was the model fit with a factor response variable?")
165+
cli::cli_abort(
166+
c("`kknn` model does not appear to use class predictions.",
167+
"i" = "Was the model fit with a factor response variable?")
168168
)
169169
}
170170
x

R/rand_forest.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ translate.rand_forest <- function(x, engine = x$engine, ...) {
9999

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

122122
if (any(names(arg_vals) == "importance")) {
123123
if (isTRUE(is.logical(quo_get_expr(arg_vals$importance)))) {
124-
rlang::abort("`importance` should be a character value. See ?ranger::ranger.")
124+
cli::cli_abort(
125+
c(
126+
"{.arg importance} should be a character value.",
127+
"i" = "See ?ranger::ranger."
128+
)
129+
)
125130
}
126131
}
127132
# unless otherwise specified, classification models are probability forests

R/rand_forest_data.R

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ ranger_confint <- function(object, new_data, ...) {
6464
if (object$fit$forest$treetype == "Probability estimation") {
6565
res <- ranger_class_confint(object, new_data, ...)
6666
} else {
67-
rlang::abort(
68-
glue::glue(
69-
"Cannot compute confidence intervals for a ranger forest ",
70-
"of type {object$fit$forest$treetype}."
71-
)
67+
cli::cli_abort(
68+
"Cannot compute confidence intervals for a ranger forest
69+
of type {.val {object$fit$forest$treetype}}."
7270
)
7371
}
7472
}
@@ -204,10 +202,10 @@ set_pred(
204202
value = list(
205203
pre = function(x, object) {
206204
if (object$fit$forest$treetype != "Probability estimation")
207-
rlang::abort(
208-
glue::glue(
209-
"`ranger` model does not appear to use class probabilities. Was ",
210-
"the model fit with `probability = TRUE`?"
205+
cli::cli_abort(
206+
c(
207+
"`ranger` model does not appear to use class probabilities.",
208+
"i" = "Was the model fit with `probability = TRUE`?"
211209
)
212210
)
213211
x

R/svm_linear.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ translate.svm_linear <- function(x, engine = x$engine, ...) {
105105
arg_vals$svr_eps <- 0.1
106106
if (!is_null(liblinear_type))
107107
if(!liblinear_type %in% 11:13)
108-
rlang::abort(
109-
paste0("The LiblineaR engine argument of `type` = ",
110-
liblinear_type,
111-
" does not correspond to an SVM regression model.")
108+
cli::cli_abort(
109+
"The LiblineaR engine argument {.code type = {liblinear_type}}
110+
does not correspond to an SVM regression model."
112111
)
113112
} else if (x$mode == "classification") {
114113
if (!is_null(liblinear_type))

R/svm_rbf_data.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ set_pred(
296296
value = list(
297297
pre = function(x, object) {
298298
if (!object$fit$predict.prob) {
299-
rlang::abort(
300-
paste0("`svm` model does not appear to use class probabilities. Was ",
301-
"the model fit with `predict.prob = TRUE`?")
299+
cli::cli_abort(
300+
c(
301+
"The model does not appear to use class probabilities.",
302+
"i" = "Was the model fit with {.code predict.prob = TRUE}?"
303+
)
302304
)
303305
}
304306
x

0 commit comments

Comments
 (0)