Skip to content

Commit 02be9dc

Browse files
committed
use check_ functions for penalty
1 parent 3277863 commit 02be9dc

File tree

8 files changed

+8
-35
lines changed

8 files changed

+8
-35
lines changed

R/discrim_linear.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,7 @@ check_args.discrim_linear <- function(object, call = rlang::caller_env()) {
8484

8585
args <- lapply(object$args, rlang::eval_tidy)
8686

87-
if (all(is.numeric(args$penalty)) && any(args$penalty < 0)) {
88-
cli::cli_abort(
89-
"The amount of regularization, {.arg penalty}, should be {.code >= 0}.",
90-
call = call
91-
)
92-
}
87+
check_number_decimal(args$penalty, min = 0, allow_null = TRUE, call = call, arg = "penalty")
9388

9489
invisible(object)
9590
}

R/linear_reg.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,7 @@ check_args.linear_reg <- function(object, call = rlang::caller_env()) {
111111
args <- lapply(object$args, rlang::eval_tidy)
112112

113113
check_number_decimal(args$mixture, min = 0, max = 1, allow_null = TRUE, call = call, arg = "mixture")
114-
115-
if (all(is.numeric(args$penalty)) && any(args$penalty < 0)) {
116-
cli::cli_abort(
117-
"The amount of regularization, {.arg penalty}, should be {.code >= 0}.",
118-
call = call
119-
)
120-
}
114+
check_number_decimal(args$penalty, min = 0, allow_null = TRUE, call = call, arg = "penalty")
121115

122116
invisible(object)
123117
}

R/logistic_reg.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,7 @@ check_args.logistic_reg <- function(object, call = rlang::caller_env()) {
140140
args <- lapply(object$args, rlang::eval_tidy)
141141

142142
check_number_decimal(args$mixture, min = 0, max = 1, allow_null = TRUE, call = call, arg = "mixture")
143-
144-
if (all(is.numeric(args$penalty)) && any(args$penalty < 0))
145-
cli::cli_abort(
146-
"The amount of regularization, {.arg penalty}, should be {.code >= 0}.",
147-
call = call
148-
)
143+
check_number_decimal(args$penalty, min = 0, allow_null = TRUE, call = call, arg = "penalty")
149144

150145
if (object$engine == "LiblineaR") {
151146
if (is.numeric(args$mixture) && !args$mixture %in% 0:1) {

R/multinom_reg.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,8 @@ check_args.multinom_reg <- function(object, call = rlang::caller_env()) {
105105
args <- lapply(object$args, rlang::eval_tidy)
106106

107107
check_number_decimal(args$mixture, min = 0, max = 1, allow_null = TRUE, call = call, arg = "mixture")
108+
check_number_decimal(args$penalty, min = 0, allow_null = TRUE, call = call, arg = "penalty")
108109

109-
if (all(is.numeric(args$penalty)) && any(args$penalty < 0)) {
110-
cli::cli_abort(
111-
"The amount of regularization, {.arg penalty}, should be {.code >= 0}.",
112-
call = call
113-
)
114-
}
115110
invisible(object)
116111
}
117112

R/poisson_reg.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,7 @@ check_args.poisson_reg <- function(object, call = rlang::caller_env()) {
106106
args <- lapply(object$args, rlang::eval_tidy)
107107

108108
check_number_decimal(args$mixture, min = 0, max = 1, allow_null = TRUE, call = call, arg = "mixture")
109-
110-
if (all(is.numeric(args$penalty)) && any(args$penalty < 0)) {
111-
cli::cli_abort(
112-
"The amount of regularization, {.arg penalty}, should be {.code >= 0}.",
113-
call = call
114-
)
115-
}
109+
check_number_decimal(args$penalty, min = 0, allow_null = TRUE, call = call, arg = "penalty")
116110

117111
invisible(object)
118112
}

tests/testthat/_snaps/linear_reg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@
3939
fit(spec, compounds ~ ., hpc)
4040
Condition
4141
Error in `fit()`:
42-
! The amount of regularization, `penalty`, should be `>= 0`.
42+
! `penalty` must be a number larger than or equal to 0 or `NULL`, not the number -1.
4343

tests/testthat/_snaps/logistic_reg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
fit(spec, Class ~ ., lending_club)
4848
Condition
4949
Error in `fit()`:
50-
! The amount of regularization, `penalty`, should be `>= 0`.
50+
! `penalty` must be a number larger than or equal to 0 or `NULL`, not the number -1.
5151

5252
---
5353

tests/testthat/_snaps/multinom_reg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@
3333
fit(spec, class ~ ., hpc)
3434
Condition
3535
Error in `fit()`:
36-
! The amount of regularization, `penalty`, should be `>= 0`.
36+
! `penalty` must be a number larger than or equal to 0 or `NULL`, not the number -1.
3737

0 commit comments

Comments
 (0)