Skip to content

Commit 8881f14

Browse files
Merge pull request #200 from tidymodels/use-cli
2 parents 415ae25 + 13f30dd commit 8881f14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+261
-325
lines changed

R/arguments.R

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ check_eng_args <- function(args, obj, core_args) {
88
if (length(common_args) > 0) {
99
args <- args[!(names(args) %in% common_args)]
1010
common_args <- paste0(common_args, collapse = ", ")
11-
rlang::warn(
12-
glue::glue(
13-
"The following arguments cannot be manually modified ",
14-
"and were removed: {common_args}."
15-
)
11+
cli::cli_warn(
12+
"The arguments {common_args} cannot be manually modified and were removed."
1613
)
1714
}
1815
args
@@ -32,7 +29,7 @@ make_x_call <- function(object, target) {
3229
none = rlang::expr(x),
3330
data.frame = rlang::expr(maybe_data_frame(x)),
3431
matrix = rlang::expr(maybe_matrix(x)),
35-
rlang::abort(glue::glue("Invalid data type target: {target}."))
32+
cli::cli_abort("Invalid data type target: {target}.")
3633
)
3734

3835
fit_call <- make_call(
@@ -78,7 +75,7 @@ make_form_call <- function(object, env = NULL) {
7875
set_args.cluster_spec <- function(object, ...) {
7976
the_dots <- enquos(...)
8077
if (length(the_dots) == 0) {
81-
rlang::abort("Please pass at least one named argument.")
78+
cli::cli_abort("Please pass at least one named argument.")
8279
}
8380
main_args <- names(object$args)
8481
new_args <- names(the_dots)

R/augment.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ augment.cluster_fit <- function(x, new_data, ...) {
3131
stats::predict(x, new_data = new_data)
3232
)
3333
} else {
34-
rlang::abort(paste("Unknown mode:", x$spec$mode))
34+
cli::cli_abort("Unknown mode: {x$spec$mode}")
3535
}
3636
as_tibble(ret)
3737
}

R/control.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ check_control <- function(x, call = rlang::caller_env()) {
3737
abs(x - round(x)) < tol
3838
}
3939
if (!int_check(x$verbosity)) {
40-
rlang::abort("verbosity should be an integer.", call = call)
40+
cli::cli_abort("verbosity should be an integer.", call = call)
4141
}
4242
if (!is.logical(x$catch)) {
43-
rlang::abort("catch should be a logical.", call = call)
43+
cli::cli_abort("catch should be a logical.", call = call)
4444
}
4545
x
4646
}

R/convert_data.R

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
remove_intercept = TRUE
4343
) {
4444
if (!(composition %in% c("data.frame", "matrix"))) {
45-
rlang::abort("`composition` should be either 'data.frame' or 'matrix'.")
45+
cli::cli_abort(
46+
"{.arg composition} should be {.cls data.frame} or {.cls matrix}."
47+
)
4648
}
4749

4850
## Assemble model.frame call from call arguments
@@ -59,7 +61,7 @@
5961

6062
w <- as.vector(model.weights(mod_frame))
6163
if (!is.null(w) && !is.numeric(w)) {
62-
rlang::abort("`weights` must be a numeric vector")
64+
cli::cli_abort("The {.arg weights} must be a numeric vector.")
6365
}
6466

6567
# TODO: Do we actually use the offset when fitting?
@@ -124,15 +126,11 @@ check_form_dots <- function(x) {
124126
good_args <- c("subset", "weights")
125127
good_names <- names(x) %in% good_args
126128
if (any(!good_names)) {
127-
rlang::abort(
128-
glue::glue(
129-
"These argument(s) cannot be used to create the data: ",
130-
glue::glue_collapse(
131-
glue::glue("`{names(x)[!good_names]}`"),
132-
sep = ", "
133-
),
134-
". Possible arguments are: ",
135-
glue::glue_collapse(glue::glue("`{good_args}`"), sep = ", ")
129+
cli::cli_abort(
130+
c(
131+
"The argument{?s} {.code {names(x)[!good_names]}} cannot be used
132+
to create the data.",
133+
"i" = "Possible arguments are: {.code {good_args}}."
136134
)
137135
)
138136
}
@@ -159,7 +157,7 @@ local_one_hot_contrasts <- function(frame = rlang::caller_env()) {
159157
#' @keywords internal
160158
.convert_x_to_form_fit <- function(x, weights = NULL, remove_intercept = TRUE) {
161159
if (is.vector(x)) {
162-
rlang::abort("`x` cannot be a vector.")
160+
cli::cli_abort("{.arg x} cannot be a vector.")
163161
}
164162

165163
if (remove_intercept) {
@@ -182,10 +180,10 @@ local_one_hot_contrasts <- function(frame = rlang::caller_env()) {
182180

183181
if (!is.null(weights)) {
184182
if (!is.numeric(weights)) {
185-
rlang::abort("`weights` must be a numeric vector")
183+
cli::cli_abort("The {.arg weights} must be a numeric vector.")
186184
}
187185
if (length(weights) != nrow(x)) {
188-
rlang::abort(glue::glue("`weights` should have {nrow(x)} elements"))
186+
cli::cli_abort("{.arg weights} should have {nrow(x)} elements.")
189187
}
190188
}
191189

@@ -219,7 +217,9 @@ make_formula <- function(x, short = TRUE) {
219217
composition = "data.frame"
220218
) {
221219
if (!(composition %in% c("data.frame", "matrix"))) {
222-
rlang::abort("`composition` should be either 'data.frame' or 'matrix'.")
220+
cli::cli_abort(
221+
"{.arg composition} should be either {.code data.frame} or {.code matrix}."
222+
)
223223
}
224224

225225
mod_terms <- object$terms

R/engines.R

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ stop_missing_engine <- function(cls, call = rlang::caller_env()) {
4242
.groups = "drop"
4343
)
4444
if (nrow(info) == 0) {
45-
rlang::abort(glue::glue("No known engines for `{cls}()`."), call = call)
45+
cli::cli_abort("No known engines for {.fn {cls}}.", call = call)
4646
}
47-
msg <- paste0(info$msg, collapse = ", ")
48-
msg <- paste("Missing engine. Possible mode/engine combinations are:", msg)
49-
rlang::abort(msg, call = call)
47+
cli::cli_abort(
48+
c(
49+
"Missing engine.",
50+
"i" = "Possible mode/engine combinations are: {info$msg}."
51+
),
52+
call = call
53+
)
5054
}
5155

5256
load_libs <- function(x, quiet, attach = FALSE) {
@@ -86,11 +90,8 @@ check_installs <- function(x, call = rlang::caller_env()) {
8690
if (any(!is_inst)) {
8791
missing_pkg <- x$method$libs[!is_inst]
8892
missing_pkg <- paste0(missing_pkg, collapse = ", ")
89-
rlang::abort(
90-
glue::glue(
91-
"This engine requires some package installs: ",
92-
glue::glue_collapse(glue::glue("'{missing_pkg}'"), sep = ", ")
93-
),
93+
cli::cli_abort(
94+
"This engine requires installing {.pkg {missing_pkg}}.",
9495
call = call
9596
)
9697
}

R/extract.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ extract_fit_engine.cluster_fit <- function(x, ...) {
5252
if (any(names(x) == "fit")) {
5353
return(x$fit)
5454
}
55-
rlang::abort("Internal error: The model fit does not have an engine fit.")
55+
cli::cli_abort("Internal error: The model fit does not have an engine fit.")
5656
}

R/extract_cluster_assignment.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ extract_cluster_assignment <- function(object, ...) {
6969

7070
#' @export
7171
extract_cluster_assignment.cluster_spec <- function(object, ...) {
72-
rlang::abort(
73-
paste(
72+
cli::cli_abort(
73+
c(
7474
"This function requires a fitted model.",
75-
"Please use `fit()` on your cluster specification."
75+
"i" = "Please use {.fn fit} on your cluster specification."
7676
)
7777
)
7878
}
@@ -121,20 +121,20 @@ extract_cluster_assignment.hclust <- function(
121121
args <- list(...)
122122

123123
if (!is.null(args[["h"]])) {
124-
rlang::abort(
125-
paste(
126-
"Using `h` argument is not supported.",
127-
"Please use `cut_height` instead."
124+
cli::cli_abort(
125+
c(
126+
"Using {.arg h} argument is not supported.",
127+
"i" = "Please use {.arg cut_height} instead."
128128
),
129129
call = call
130130
)
131131
}
132132

133133
if (!is.null(args[["k"]])) {
134-
rlang::abort(
135-
paste(
136-
"Using `k` argument is not supported.",
137-
"Please use `num_clusters` instead."
134+
cli::cli_abort(
135+
c(
136+
"Using {.arg k} argument is not supported.",
137+
"i" = "Please use {.arg num_clusters} instead."
138138
),
139139
call = call
140140
)
@@ -149,8 +149,8 @@ extract_cluster_assignment.hclust <- function(
149149
}
150150

151151
if (is.null(num_clusters) && is.null(cut_height)) {
152-
rlang::abort(
153-
"Please specify either `num_clusters` or `cut_height`.",
152+
cli::cli_abort(
153+
"Please specify either {.arg num_clusters} or {.arg cut_height}.",
154154
call = call
155155
)
156156
}

R/extract_fit_summary.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ extract_fit_summary.cluster_spec <- function(
2828
...,
2929
call = rlang::caller_env(n = 0)
3030
) {
31-
rlang::abort(
32-
paste(
31+
cli::cli_abort(
32+
c(
3333
"This function requires a fitted model.",
34-
"Please use `fit()` on your cluster specification."
34+
"i" = "Please use {.fn fit} on your cluster specification."
3535
),
3636
call = call
3737
)

R/extract_parameter_set_dials.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ eval_call_info <- function(x) {
3636
silent = TRUE
3737
)
3838
if (inherits(res, "try-error")) {
39-
rlang::abort(
40-
glue::glue(
41-
"Error when calling {x$fun}(): {as.character(res)}"
42-
)
43-
)
39+
cli::cli_abort("Error when calling {.fn {x$fun}}: {as.character(res)}")
4440
}
4541
} else {
4642
res <- NA

R/finalize.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#' @export
2323
finalize_model_tidyclust <- function(x, parameters) {
2424
if (!inherits(x, "cluster_spec")) {
25-
rlang::abort("`x` should be a tidyclust model specification.")
25+
cli::cli_abort("{.arg x} should be a tidyclust model specification.")
2626
}
2727
parsnip::check_final_param(parameters)
2828
pset <- hardhat::extract_parameter_set_dials(x)
@@ -46,7 +46,7 @@ finalize_model_tidyclust <- function(x, parameters) {
4646
#' @export
4747
finalize_workflow_tidyclust <- function(x, parameters) {
4848
if (!inherits(x, "workflow")) {
49-
rlang::abort("`x` should be a workflow")
49+
cli::cli_abort("{.arg x} should be {.obj_type_friendly workflow}")
5050
}
5151
parsnip::check_final_param(parameters)
5252

0 commit comments

Comments
 (0)