Skip to content

Commit 979c355

Browse files
committed
closes #406
1 parent 465f1d7 commit 979c355

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

R/fit.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ fit.model_spec <-
100100
if (object$mode == "unknown") {
101101
rlang::abort("Please set the mode in the model specification.")
102102
}
103+
if (!identical(class(control), class(control_parsnip()))) {
104+
rlang::abort("The 'control' argument should have class 'control_parsnip'.")
105+
}
103106
dots <- quos(...)
104107
if (is.null(object$engine)) {
105108
eng_vals <- possible_engines(object)
@@ -189,6 +192,9 @@ fit_xy.model_spec <-
189192
control = control_parsnip(),
190193
...
191194
) {
195+
if (!identical(class(control), class(control_parsnip()))) {
196+
rlang::abort("The 'control' argument should have class 'control_parsnip'.")
197+
}
192198
object <- check_mode(object, levels(y))
193199
dots <- quos(...)
194200
if (is.null(object$engine)) {

tests/testthat/test_misc.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,22 @@ test_that('S3 method dispatch/registration', {
8585
)
8686
expect_true(tibble::is_tibble(res))
8787

88+
})
8889

90+
# ------------------------------------------------------------------------------
8991

92+
test_that('control class', {
93+
x <- linear_reg() %>% set_engine("lm")
94+
ctrl <- control_parsnip()
95+
class(ctrl) <- c("potato", "chair")
96+
expect_error(
97+
fit(x, mpg ~ ., data = mtcars, control = ctrl),
98+
"The 'control' argument should have class 'control_parsnip'"
99+
)
100+
expect_error(
101+
fit_xy(x, x = mtcars[, -1], y = mtcars$mpg, control = ctrl),
102+
"The 'control' argument should have class 'control_parsnip'"
103+
)
90104
})
91105

92106

0 commit comments

Comments
 (0)