diff --git a/R/glmnet-engines.R b/R/glmnet-engines.R index 0e6514c69..296468e49 100644 --- a/R/glmnet-engines.R +++ b/R/glmnet-engines.R @@ -361,11 +361,13 @@ format_glmnet_multinom_class <- function(pred, penalty, lvl, n_obs) { pen <- rlang::eval_tidy(x$args$penalty) if (length(pen) != 1) { - rlang::abort(c( - "For the glmnet engine, `penalty` must be a single number (or a value of `tune()`).", - glue::glue("There are {length(pen)} values for `penalty`."), - "To try multiple values for total regularization, use the tune package.", - "To predict multiple penalties, use `multi_predict()`" + cli::cli_abort(c( + "x" = "For the glmnet engine, {.arg penalty} must be a single number + (or a value of {.fn tune}).", + "!" = "There are {length(pen)} value{?s} for {.arg penalty}.", + "i" = "To try multiple values for total regularization, use the + {.pkg tune} package.", + "i" = "To predict multiple penalties, use {.fn multi_predict}." )) } } @@ -385,23 +387,19 @@ format_glmnet_multinom_class <- function(pred, penalty, lvl, n_obs) { # when using `predict()`, allow for a single lambda if (!multi) { if (length(penalty) != 1) { - rlang::abort( - glue::glue( - "`penalty` should be a single numeric value. `multi_predict()` ", - "can be used to get multiple predictions per row of data." - ) - ) + cli::cli_abort(c( + "{.arg penalty} should be a single numeric value.", + "i" = "{.fn multi_predict} can be used to get multiple predictions per row of data." + )) } } if (length(object$fit$lambda) == 1 && penalty != object$fit$lambda) { - rlang::abort( - glue::glue( - "The glmnet model was fit with a single penalty value of ", - "{object$fit$lambda}. Predicting with a value of {penalty} ", - "will give incorrect results from `glmnet()`." - ) - ) + cli::cli_abort(c( + "The glmnet model was fit with a single penalty value of + {.arg object$fit$lambda}. Predicting with a value of {.arg penalty} + will give incorrect results from `glmnet()`." + )) } penalty diff --git a/R/logistic_reg.R b/R/logistic_reg.R index 40ccf5dc5..6d0f6c6d8 100644 --- a/R/logistic_reg.R +++ b/R/logistic_reg.R @@ -98,7 +98,7 @@ translate.logistic_reg <- function(x, engine = x$engine, ...) { } else if (quo_get_expr(x$args$mixture) == 1) { arg_vals$type <- 6 ## lasso } else { - rlang::abort("For the LiblineaR engine, mixture must be 0 or 1.") + cli::cli_abort("For the LiblineaR engine, {.arg mixture} must be 0 or 1.") } } x$method$fit$args <- arg_vals @@ -153,7 +153,7 @@ check_args.logistic_reg <- function(object, call = rlang::caller_env()) { call = call ) } - + if ((!is.null(args$penalty)) && args$penalty == 0) { cli::cli_abort( "For the {.pkg LiblineaR} engine, {.arg penalty} must be {.code > 0}, \\ diff --git a/R/mars.R b/R/mars.R index f4ad10ae7..49321b3f7 100644 --- a/R/mars.R +++ b/R/mars.R @@ -161,14 +161,14 @@ multi_predict._earth <- object$fit$call[[i]] <- eval_tidy(object$fit$call[[i]]) } - msg <- - paste("Please use `keepxy = TRUE` as an option to enable submodel", - "predictions with `earth`.") + msg <- + c("x" = "Please use {.code keepxy = TRUE} as an option to enable submodel + predictions with earth.") if (any(names(object$fit$call) == "keepxy")) { if (!isTRUE(object$fit$call$keepxy)) - rlang::abort(msg) + cli::cli_abort(msg) } else { - rlang::abort(msg) + cli::cli_abort(msg) } if (is.null(type)) { diff --git a/R/mlp.R b/R/mlp.R index fa3cf097c..b35dbe32c 100644 --- a/R/mlp.R +++ b/R/mlp.R @@ -148,7 +148,7 @@ check_args.mlp <- function(object, call = rlang::caller_env()) { class2ind <- function (x, drop2nd = FALSE) { if (!is.factor(x)) - rlang::abort("`x` should be a factor") + cli::cli_abort(c("x" = "{.arg x} should be a factor.")) y <- model.matrix( ~ x - 1) colnames(y) <- gsub("^x", "", colnames(y)) attributes(y)$assign <- NULL @@ -195,7 +195,7 @@ keras_mlp <- rlang::arg_match(activation, act_funs,) if (penalty > 0 & dropout > 0) { - rlang::abort("Please use either dropoput or weight decay.", call. = FALSE) + cli::cli_abort("Please use either dropout or weight decay.", call = NULL) } if (!is.matrix(x)) { x <- as.matrix(x) diff --git a/tests/testthat/_snaps/translate.md b/tests/testthat/_snaps/translate.md index 4bd08b4ae..ff354245c 100644 --- a/tests/testthat/_snaps/translate.md +++ b/tests/testthat/_snaps/translate.md @@ -504,10 +504,10 @@ translate_args(basic %>% set_engine("glmnet")) Condition Error in `.check_glmnet_penalty_fit()`: - ! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). - * There are 0 values for `penalty`. - * To try multiple values for total regularization, use the tune package. - * To predict multiple penalties, use `multi_predict()` + x For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). + ! There are 0 values for `penalty`. + i To try multiple values for total regularization, use the tune package. + i To predict multiple penalties, use `multi_predict()`. --- @@ -555,10 +555,10 @@ translate_args(mixture %>% set_engine("glmnet")) Condition Error in `.check_glmnet_penalty_fit()`: - ! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). - * There are 0 values for `penalty`. - * To try multiple values for total regularization, use the tune package. - * To predict multiple penalties, use `multi_predict()` + x For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). + ! There are 0 values for `penalty`. + i To try multiple values for total regularization, use the tune package. + i To predict multiple penalties, use `multi_predict()`. --- @@ -688,10 +688,10 @@ translate_args(basic %>% set_engine("glmnet")) Condition Error in `.check_glmnet_penalty_fit()`: - ! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). - * There are 0 values for `penalty`. - * To try multiple values for total regularization, use the tune package. - * To predict multiple penalties, use `multi_predict()` + x For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). + ! There are 0 values for `penalty`. + i To try multiple values for total regularization, use the tune package. + i To predict multiple penalties, use `multi_predict()`. --- @@ -827,10 +827,10 @@ translate_args(mixture %>% set_engine("glmnet")) Condition Error in `.check_glmnet_penalty_fit()`: - ! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). - * There are 0 values for `penalty`. - * To try multiple values for total regularization, use the tune package. - * To predict multiple penalties, use `multi_predict()` + x For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). + ! There are 0 values for `penalty`. + i To try multiple values for total regularization, use the tune package. + i To predict multiple penalties, use `multi_predict()`. --- @@ -968,10 +968,10 @@ translate_args(mixture_v %>% set_engine("glmnet")) Condition Error in `.check_glmnet_penalty_fit()`: - ! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). - * There are 0 values for `penalty`. - * To try multiple values for total regularization, use the tune package. - * To predict multiple penalties, use `multi_predict()` + x For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). + ! There are 0 values for `penalty`. + i To try multiple values for total regularization, use the tune package. + i To predict multiple penalties, use `multi_predict()`. --- @@ -1334,10 +1334,10 @@ translate_args(basic %>% set_engine("glmnet")) Condition Error in `.check_glmnet_penalty_fit()`: - ! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). - * There are 0 values for `penalty`. - * To try multiple values for total regularization, use the tune package. - * To predict multiple penalties, use `multi_predict()` + x For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). + ! There are 0 values for `penalty`. + i To try multiple values for total regularization, use the tune package. + i To predict multiple penalties, use `multi_predict()`. --- @@ -1552,10 +1552,10 @@ basic_incomplete %>% translate_args() Condition Error in `.check_glmnet_penalty_fit()`: - ! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). - * There are 0 values for `penalty`. - * To try multiple values for total regularization, use the tune package. - * To predict multiple penalties, use `multi_predict()` + x For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). + ! There are 0 values for `penalty`. + i To try multiple values for total regularization, use the tune package. + i To predict multiple penalties, use `multi_predict()`. # arguments (rand_forest)