Skip to content

Commit 1fb7988

Browse files
committed
check values first (and evaluate them)
1 parent fb8d78b commit 1fb7988

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

R/linear_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ translate.linear_reg <- function(x, engine = x$engine, ...) {
107107
x <- translate.default(x, engine, ...)
108108

109109
if (engine == "glmnet") {
110+
check_glmnet_penalty(x)
110111
if (any(names(x$eng_args) == "path_values")) {
111112
# Since we decouple the parsnip `penalty` argument from being the same
112113
# as the glmnet `lambda` value, this allows users to set the path
@@ -122,7 +123,6 @@ translate.linear_reg <- function(x, engine = x$engine, ...) {
122123
# Since the `fit` information is gone for the penalty, we need to have an
123124
# evaluated value for the parameter.
124125
x$args$penalty <- rlang::eval_tidy(x$args$penalty)
125-
check_glmnet_penalty(x)
126126
}
127127
x
128128
}

R/logistic_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ translate.logistic_reg <- function(x, engine = x$engine, ...) {
109109
arg_names <- names(arg_vals)
110110

111111
if (engine == "glmnet") {
112+
check_glmnet_penalty(x)
112113
if (any(names(x$eng_args) == "path_values")) {
113114
# Since we decouple the parsnip `penalty` argument from being the same
114115
# as the glmnet `lambda` value, this allows users to set the path
@@ -124,7 +125,6 @@ translate.logistic_reg <- function(x, engine = x$engine, ...) {
124125
# Since the `fit` information is gone for the penalty, we need to have an
125126
# evaluated value for the parameter.
126127
x$args$penalty <- rlang::eval_tidy(x$args$penalty)
127-
check_glmnet_penalty(x)
128128
}
129129

130130
if (engine == "LiblineaR") {

R/misc.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,12 @@ stan_conf_int <- function(object, newdata) {
324324
}
325325

326326
check_glmnet_penalty <- function(x) {
327-
if (length(x$args$penalty) != 1) {
327+
pen <- rlang::eval_tidy(x$args$penalty)
328+
329+
if (length(pen) != 1) {
328330
rlang::abort(c(
329331
"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`."),
332+
glue::glue("There are {length(pen)} values for `penalty`."),
331333
"To try multiple values for total regularization, use the tune package.",
332334
"To predict multiple penalties, use `multi_predict()`"
333335
))

R/multinom_reg.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ translate.multinom_reg <- function(x, engine = x$engine, ...) {
100100
x <- translate.default(x, engine, ...)
101101

102102
if (engine == "glmnet") {
103+
check_glmnet_penalty(x)
103104
if (any(names(x$eng_args) == "path_values")) {
104105
# Since we decouple the parsnip `penalty` argument from being the same
105106
# as the glmnet `lambda` value, this allows users to set the path

0 commit comments

Comments
 (0)