Skip to content

Commit 777f48a

Browse files
committed
Merge branch 'sparse-input' of github.com:tidymodels/parsnip into sparse-input
2 parents 616b548 + f0f92e9 commit 777f48a

15 files changed

+175
-119
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
* `fit_xy()` can now take dgCMatrix input for `x` argument (#1121).
44

5+
* Transitioned package errors and warnings to use cli (#1147 and #1148 by
6+
@shum461, #1153 by @RobLBaker and @wright13, #1154 by @JamesHWade, #1160,
7+
#1161).
8+
59
* `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).
610

711
* 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).

R/bart.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ update.bart <-
142142
#' @param std_err Attach column for standard error of prediction or not.
143143
bartMachine_interval_calc <- function(new_data, obj, ci = TRUE, level = 0.95) {
144144
if (obj$spec$mode == "classification") {
145-
rlang::abort("In bartMachine: Prediction intervals are not possible for classification")
145+
cli::cli_abort(
146+
"Prediction intervals are not possible for classification"
147+
)
146148
}
147149
get_std_err <- obj$spec$method$pred$pred_int$extras$std_error
148150

R/boost_tree.R

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,9 @@ translate.boost_tree <- function(x, engine = x$engine, ...) {
134134

135135
if (engine == "spark") {
136136
if (x$mode == "unknown") {
137-
rlang::abort(
138-
glue::glue(
139-
"For spark boosted trees models, the mode cannot be 'unknown' ",
140-
"if the specification is to be translated."
141-
)
137+
cli::cli_abort(
138+
"For spark boosted tree models, the mode cannot be {.val unknown}
139+
if the specification is to be translated."
142140
)
143141
} else {
144142
arg_vals$type <- x$mode
@@ -172,7 +170,7 @@ check_args.boost_tree <- function(object, call = rlang::caller_env()) {
172170
check_number_decimal(args$sample_size, min = 0, max = 1, allow_null = TRUE, call = call, arg = "sample_size")
173171
check_number_whole(args$tree_depth, min = 0, allow_null = TRUE, call = call, arg = "tree_depth")
174172
check_number_whole(args$min_n, min = 0, allow_null = TRUE, call = call, arg = "min_n")
175-
173+
176174
invisible(object)
177175
}
178176

@@ -229,15 +227,15 @@ xgb_train <- function(
229227
num_class <- length(levels(y))
230228

231229
if (!is.numeric(validation) || validation < 0 || validation >= 1) {
232-
rlang::abort("`validation` should be on [0, 1).")
230+
cli::cli_abort("{.arg validation} should be on [0, 1).")
233231
}
234232

235233
if (!is.null(early_stop)) {
236234
if (early_stop <= 1) {
237-
rlang::abort(paste0("`early_stop` should be on [2, ", nrounds, ")."))
235+
cli::cli_abort("{.arg early_stop} should be on [2, {nrounds}).")
238236
} else if (early_stop >= nrounds) {
239237
early_stop <- nrounds - 1
240-
rlang::warn(paste0("`early_stop` was reduced to ", early_stop, "."))
238+
cli::cli_warn("{.arg early_stop} was reduced to {early_stop}.")
241239
}
242240
}
243241

@@ -252,7 +250,7 @@ xgb_train <- function(
252250

253251

254252
if (!is.numeric(subsample) || subsample < 0 || subsample > 1) {
255-
rlang::abort("`subsample` should be on [0, 1].")
253+
cli::cli_abort("{.arg subsample} should be on [0, 1].")
256254
}
257255

258256
# initialize
@@ -268,9 +266,13 @@ xgb_train <- function(
268266
}
269267

270268
if (min_child_weight > n) {
271-
msg <- paste0(min_child_weight, " samples were requested but there were ",
272-
n, " rows in the data. ", n, " will be used.")
273-
rlang::warn(msg)
269+
cli::cli_warn(
270+
c(
271+
"!" = "{min_child_weight} samples were requested but there were {n} rows
272+
in the data.",
273+
"i" = "{n} will be used."
274+
)
275+
)
274276
min_child_weight <- min(min_child_weight, n)
275277
}
276278

@@ -369,14 +371,16 @@ recalc_param <- function(x, counts, denom) {
369371
x
370372
}
371373

372-
maybe_proportion <- function(x, nm) {
374+
maybe_proportion <- function(x, nm, call = rlang::caller_env()) {
373375
if (x < 1) {
374-
msg <- paste0(
375-
"The option `counts = TRUE` was used but parameter `", nm,
376-
"` was given as ", signif(x, 3), ". Please use a value >= 1 or use ",
377-
"`counts = FALSE`."
376+
cli::cli_abort(
377+
c(
378+
"The option `counts = TRUE` was used but {.arg {nm}} was given
379+
as {signif(x, 3)}.",
380+
"i" = "Please use a value >= 1 or use {.code counts = FALSE}."
381+
),
382+
call = call
378383
)
379-
rlang::abort(msg)
380384
}
381385
}
382386

@@ -418,7 +422,9 @@ as_xgb_data <- function(x, y, validation = 0, weights = NULL, event_level = "fir
418422
y <- as.numeric(y) - 1
419423
}
420424
} else {
421-
if (event_level == "second") rlang::warn("`event_level` can only be set for binary variables.")
425+
if (event_level == "second") {
426+
cli::cli_warn("{.arg event_level} can only be set for binary outcomes.")
427+
}
422428
y <- as.numeric(y) - 1
423429
}
424430
}
@@ -573,15 +579,19 @@ C5.0_train <-
573579

574580
n <- nrow(x)
575581
if (n == 0) {
576-
rlang::abort("There are zero rows in the predictor set.")
582+
cli::cli_abort("There are zero rows in the predictor set.")
577583
}
578584

579585

580586
ctrl <- call2("C5.0Control", .ns = "C50")
581587
if (minCases > n) {
582-
msg <- paste0(minCases, " samples were requested but there were ",
583-
n, " rows in the data. ", n, " will be used.")
584-
rlang::warn(msg)
588+
589+
cli::cli_warn(
590+
c(
591+
"!" = "{minCases} samples were requested but there were {n} rows in the data.",
592+
"i" = "{n} will be used."
593+
)
594+
)
585595
minCases <- n
586596
}
587597
ctrl$minCases <- minCases

R/decision_tree.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ translate.decision_tree <- function(x, engine = x$engine, ...) {
9797

9898
if (x$engine == "spark") {
9999
if (x$mode == "unknown") {
100-
rlang::abort(
101-
glue::glue(
102-
"For spark decision tree models, the mode cannot be 'unknown' ",
103-
"if the specification is to be translated."
104-
)
100+
cli::cli_abort(
101+
"For spark decision tree models, the mode cannot be {.val unknown}
102+
if the specification is to be translated."
105103
)
106104
}
107105
}

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

0 commit comments

Comments
 (0)