Skip to content

Commit 2d9c1d3

Browse files
committed
moved check to function; small mesage edits
1 parent 5acfdae commit 2d9c1d3

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

R/linear_reg.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,7 @@ 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-
}
115+
check_glmnet_penalty(x)
122116
}
123117

124118
x

R/logistic_reg.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,7 @@ 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-
}
118+
check_glmnet_penalty(x)
125119
}
126120

127121
if (engine == "LiblineaR") {

R/misc.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,13 @@ stan_conf_int <- function(object, newdata) {
323323
rlang::eval_tidy(fn)
324324
}
325325

326-
326+
check_glmnet_penalty <- function(x) {
327+
if (length(x$args$penalty) != 1) {
328+
rlang::abort(c(
329+
"For the glmnet engine, `penalty` must be a single number (or a value of `tune()`).",
330+
glue::glue("There are {length(x$args$penalty)} values for `penalty`."),
331+
"To try multiple values for total regularization, use the tune package.",
332+
"To predict multiple penalties, use `multi_predict()`"
333+
))
334+
}
335+
}

0 commit comments

Comments
 (0)