Skip to content

Commit 83c5900

Browse files
committed
Error for glmnet models is there is not exactly one value for penalty
1 parent b1cb0bd commit 83c5900

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

R/linear_reg.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ translate.linear_reg <- function(x, engine = x$engine, ...) {
112112
# Since the `fit` information is gone for the penalty, we need to have an
113113
# evaluated value for the parameter.
114114
x$args$penalty <- rlang::eval_tidy(x$args$penalty)
115+
if (length(x$args$penalty) != 1) {
116+
rlang::abort(c(
117+
"For the glmnet engine, `penalty` must be a single number.",
118+
glue::glue("There are {length(x$args$penalty)} values for `penalty`."),
119+
"To try multiple values for total regularization, use the tune package."
120+
))
121+
}
115122
}
116123

117124
x

R/logistic_reg.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ translate.logistic_reg <- function(x, engine = x$engine, ...) {
115115
# Since the `fit` information is gone for the penalty, we need to have an
116116
# evaluated value for the parameter.
117117
x$args$penalty <- rlang::eval_tidy(x$args$penalty)
118+
if (length(x$args$penalty) != 1) {
119+
rlang::abort(c(
120+
"For the glmnet engine, `penalty` must be a single number.",
121+
glue::glue("There are {length(x$args$penalty)} values for `penalty`."),
122+
"To try multiple values for total regularization, use the tune package."
123+
))
124+
}
118125
}
119126

120127
if (engine == "LiblineaR") {

0 commit comments

Comments
 (0)