Skip to content

Commit 883624b

Browse files
committed
Merge commit 'd3744d2e9106b4e04761bba8f9c0605e4ac949d2'
2 parents cc4e2e5 + d3744d2 commit 883624b

Some content is hidden

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

57 files changed

+388
-226
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: parsnip
22
Title: A Common API to Modeling and Analysis Functions
3-
Version: 1.2.1.9001
3+
Version: 1.2.1.9002
44
Authors@R: c(
55
person("Max", "Kuhn", , "[email protected]", role = c("aut", "cre")),
66
person("Davis", "Vaughan", , "[email protected]", role = "aut"),

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77
* Transitioned package errors and warnings to use cli (#1147 and #1148 by
88
@shum461, #1153 by @RobLBaker and @wright13, #1154 by @JamesHWade, #1160,
9-
#1161).
9+
#1161, #1081).
1010

1111
* `fit_xy()` currently raises an error for `gen_additive_mod()` model specifications as the default engine (`"mgcv"`) specifies smoothing terms in model formulas. However, some engines specify smooths via additional arguments, in which case the restriction on `fit_xy()` is excessive. parsnip will now only raise an error when fitting a `gen_additive_mod()` with `fit_xy()` when using the `"mgcv"` engine (#775).
1212

1313
* Aligned `null_model()` with other model types; the model type now has an engine argument that defaults to `"parsnip"` and is checked with the same machinery that checks other model types in the package (#1083).
1414

1515
* New `extract_fit_time()` method has been added that returns the time it took to train the model (#853).
1616

17+
* Ensure that `knit_engine_docs()` has the required packages installed (#1156).
18+
1719

1820
# parsnip 1.2.1
1921

R/aaa_multi_predict.R

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#' @export
2020
multi_predict <- function(object, ...) {
2121
if (inherits(object$fit, "try-error")) {
22-
rlang::warn("Model fit failed; cannot make predictions.")
22+
cli::cli_warn("Model fit failed; cannot make predictions.")
2323
return(NULL)
2424
}
2525
check_for_newdata(...)
@@ -28,17 +28,19 @@ multi_predict <- function(object, ...) {
2828

2929
#' @export
3030
#' @rdname multi_predict
31-
multi_predict.default <- function(object, ...)
32-
rlang::abort(
33-
glue::glue(
34-
"No `multi_predict` method exists for objects with classes ",
35-
glue::glue_collapse(glue::glue("'{class(object)}'"), sep = ", ")
36-
)
37-
)
31+
multi_predict.default <- function(object, ...) {
32+
cli::cli_abort(
33+
"No {.fun multi_predict} method exists for objects with classes
34+
{.cls {class(object)}}."
35+
)
36+
}
3837

3938
#' @export
4039
predict.model_spec <- function(object, ...) {
41-
rlang::abort("You must use `fit()` on your model specification before you can use `predict()`.")
40+
cli::cli_abort(
41+
"You must {.fun fit} your model specification
42+
before you can use {.fun predict}."
43+
)
4244
}
4345

4446
#' Tools for models that predict on sub-models

R/adds.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' @export
88
add_rowindex <- function(x) {
99
if (!is.data.frame(x)) {
10-
rlang::abort("`x` should be a data frame.")
10+
cli::cli_abort("{.arg x} should be a data frame.")
1111
}
1212
x <- dplyr::mutate(x, .row = seq_len(nrow(x)))
1313
x

R/arguments.R

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ check_eng_args <- function(args, obj, core_args) {
2222
if (length(common_args) > 0) {
2323
args <- args[!(names(args) %in% common_args)]
2424
common_args <- paste0(common_args, collapse = ", ")
25-
rlang::warn(glue::glue("The following arguments cannot be manually modified ",
26-
"and were removed: {common_args}."))
25+
cli::cli_warn(
26+
"The argument{?s} {.arg {common_args}} cannot be manually
27+
modified and {?was/were} removed."
28+
)
2729
}
2830
args
2931
}
@@ -56,7 +58,7 @@ set_args <- function(object, ...) {
5658
set_args.model_spec <- function(object, ...) {
5759
the_dots <- enquos(...)
5860
if (length(the_dots) == 0)
59-
rlang::abort("Please pass at least one named argument.")
61+
cli::cli_abort("Please pass at least one named argument.")
6062
main_args <- names(object$args)
6163
new_args <- names(the_dots)
6264
for (i in new_args) {
@@ -263,7 +265,7 @@ make_xy_call <- function(object, target, env) {
263265
data.frame = rlang::expr(maybe_data_frame(x)),
264266
matrix = rlang::expr(maybe_matrix(x)),
265267
dgCMatrix = rlang::expr(maybe_sparse_matrix(x)),
266-
rlang::abort(glue::glue("Invalid data type target: {target}."))
268+
cli::cli_abort("Invalid data type target: {target}.")
267269
)
268270
if (uses_weights) {
269271
object$method$fit$args[[ unname(data_args["weights"]) ]] <- rlang::expr(weights)
@@ -317,9 +319,13 @@ min_cols <- function(num_cols, source) {
317319
p <- ncol(source)
318320
}
319321
if (num_cols > p) {
320-
msg <- paste0(num_cols, " columns were requested but there were ", p,
321-
" predictors in the data. ", p, " will be used.")
322-
rlang::warn(msg)
322+
cli::cli_warn(
323+
c(
324+
"!" = "{num_cols} column{?s} {?was/were} requested but there {cli::qty(p)} {?was/were}
325+
{p} predictor{?s} in the data.",
326+
"i" = "{p} predictor{?s} will be used."
327+
)
328+
)
323329
num_cols <- p
324330
}
325331

@@ -336,9 +342,14 @@ min_rows <- function(num_rows, source, offset = 0) {
336342
}
337343

338344
if (num_rows > n - offset) {
339-
msg <- paste0(num_rows, " samples were requested but there were ", n,
340-
" rows in the data. ", n - offset, " will be used.")
341-
rlang::warn(msg)
345+
cli::cli_warn(
346+
c(
347+
"!" = "{num_rows} sample{?s} {?was/were} requested but there were
348+
{n} rows in the data.",
349+
"i" = "{n - offset} sample{?s} will be used."
350+
)
351+
)
352+
342353
num_rows <- n - offset
343354
}
344355

R/augment.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ augment.model_fit <- function(x, new_data, eval_time = NULL, ...) {
8686
"regression" = augment_regression(x, new_data),
8787
"classification" = augment_classification(x, new_data),
8888
"censored regression" = augment_censored(x, new_data, eval_time = eval_time),
89-
rlang::abort(paste("Unknown mode:", x$spec$mode))
89+
cli::cli_abort(
90+
c(
91+
"Unknown mode {.val {x$spec$mode}}.",
92+
"i" = "Model mode should be one of {.or {.val {all_modes}}}."
93+
)
94+
)
9095
)
9196
tibble::new_tibble(res)
9297
}

R/autoplot.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ map_glmnet_coefs <- function(x) {
4444
# work. If an object is loaded from a new session, they will need to load the
4545
# package.
4646
if (is.null(coefs)) {
47-
rlang::abort("Please load the glmnet package before running `autoplot()`.")
47+
cli::cli_abort(
48+
"Please load the {.pkg glmnet} package before running {.fun autoplot}."
49+
)
4850
}
4951
p <- x$dim[1]
5052
if (is.list(coefs)) {
@@ -161,8 +163,7 @@ check_penalty_value <- function(x) {
161163
cl <- match.call()
162164
arg_val <- as.character(cl$x)
163165
if (!is.vector(x) || length(x) != 1 || !is.numeric(x) || x < 0) {
164-
msg <- paste0("Argument '", arg_val, "' should be a single, non-negative value.")
165-
rlang::abort(msg)
166+
cli::cli_abort("{.arg {arg_val}} should be a single, non-negative value.")
166167
}
167168
invisible(x)
168169
}

R/case_weights.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ case_weights_allowed <- function(spec) {
8787
get_from_env(paste0(mod_type, "_fit")) %>%
8888
dplyr::filter(engine == mod_eng & mode == mod_mode)
8989
if (nrow(model_info) != 1) {
90-
rlang::abort(
91-
glue::glue(
92-
"Error in getting model information for model {mod_type} with engine {mod_eng} and mode {mod_mode}."
93-
)
90+
cli::cli_abort(
91+
"Error in getting model information for model {mod_type} with
92+
engine {mod_eng} and mode {mod_mode}."
9493
)
9594
}
9695
# If weights are used, they are protected data arguments with the canonical

R/condense_control.R

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,12 @@
2323
condense_control <- function(x, ref) {
2424
mismatch <- setdiff(names(ref), names(x))
2525
if (length(mismatch)) {
26-
rlang::abort(
26+
cli::cli_abort(
2727
c(
28-
glue::glue(
29-
"Object of class `{class(x)[1]}` cannot be coerced to ",
30-
"object of class `{class(ref)[1]}`."
31-
),
32-
"The following arguments are missing:",
33-
glue::glue_collapse(
34-
glue::single_quote(mismatch),
35-
sep = ", ", last = ", and "
36-
)
28+
"Object of class {.cls class(x)[1]} cannot be coerced to
29+
object of class {.cls class(ref)[1]}.",
30+
"i" = "{cli::qty(mismatch)} The argument{?s} {.arg {mismatch}}
31+
{?is/are} missing."
3732
)
3833
)
3934
}

R/contr_one_hot.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
#' @export
1717
contr_one_hot <- function(n, contrasts = TRUE, sparse = FALSE) {
1818
if (sparse) {
19-
rlang::warn("`sparse = TRUE` not implemented for `contr_one_hot()`.")
19+
cli::cli_warn("{.code sparse = TRUE} not implemented for {.fun contr_one_hot}.")
2020
}
2121

2222
if (!contrasts) {
23-
rlang::warn("`contrasts = FALSE` not implemented for `contr_one_hot()`.")
23+
cli::cli_warn("{.code contrasts = FALSE} not implemented for {.fun contr_one_hot}.")
2424
}
2525

2626
if (is.character(n)) {
@@ -30,12 +30,12 @@ contr_one_hot <- function(n, contrasts = TRUE, sparse = FALSE) {
3030
n <- as.integer(n)
3131

3232
if (length(n) != 1L) {
33-
rlang::abort("`n` must have length 1 when an integer is provided.")
33+
cli::cli_abort("{.arg n} must have length 1 when an integer is provided.")
3434
}
3535

3636
names <- as.character(seq_len(n))
3737
} else {
38-
rlang::abort("`n` must be a character vector or an integer of size 1.")
38+
cli::cli_abort("{.arg n} must be a character vector or an integer of size 1.")
3939
}
4040

4141
out <- diag(n)

0 commit comments

Comments
 (0)