Skip to content

Commit 1ec763a

Browse files
committed
address uninformative error for set_engine(NULL) (closes #1199)
1 parent 9bb5d0a commit 1ec763a

File tree

11 files changed

+21
-32
lines changed

11 files changed

+21
-32
lines changed

R/engines.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ set_engine.model_spec <- function(object, engine, ...) {
124124
check_spec_mode_engine_val(mod_type, object$engine, object$mode)
125125
}
126126

127-
if (object$engine == "liquidSVM") {
127+
if (!is.null(object$engine) && object$engine == "liquidSVM") {
128128
lifecycle::deprecate_warn(
129129
"0.1.6",
130130
"set_engine(engine = 'cannot be liquidSVM')",

tests/testthat/_snaps/nearest_neighbor.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@
2323
Error in `nearest_neighbor()`:
2424
! "reallyunknown" is not a known mode for model `nearest_neighbor()`.
2525

26-
---
27-
28-
Code
29-
nearest_neighbor() %>% set_engine(NULL)
30-
Condition
31-
Error in `if (object$engine == "liquidSVM") ...`:
32-
! argument is of length zero
33-
3426
# check_args() works
3527

3628
Code

tests/testthat/_snaps/rand_forest.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
# bad input
1919

2020
Code
21-
translate(rand_forest(mode = "classification") %>% set_engine(NULL))
22-
Condition
23-
Error in `if (object$engine == "liquidSVM") ...`:
24-
! argument is of length zero
21+
res <- translate(rand_forest(mode = "classification") %>% set_engine(NULL))
22+
Message
23+
Used `engine = 'ranger'` for translation.
2524

2625
---
2726

tests/testthat/_snaps/surv_reg.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
---
3232

3333
Code
34-
translate(surv_reg() %>% set_engine(NULL))
35-
Condition
36-
Error in `if (object$engine == "liquidSVM") ...`:
37-
! argument is of length zero
34+
res <- translate(surv_reg() %>% set_engine(NULL))
35+
Message
36+
Used `engine = 'survival'` for translation.
3837

3938
# deprecation warning
4039

tests/testthat/_snaps/svm_linear.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
Code
2121
translate(svm_linear(mode = "regression") %>% set_engine(NULL))
2222
Condition
23-
Error in `if (object$engine == "liquidSVM") ...`:
24-
! argument is of length zero
23+
Error in `translate.default()`:
24+
! Please set an engine.
2525

2626
---
2727

tests/testthat/_snaps/svm_poly.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
---
2727

2828
Code
29-
svm_poly() %>% set_engine(NULL)
29+
svm_poly() %>% set_engine(NULL) %>% translate()
3030
Condition
31-
Error in `if (object$engine == "liquidSVM") ...`:
32-
! argument is of length zero
31+
Error in `translate.default()`:
32+
! Please set an engine.
3333

tests/testthat/_snaps/svm_rbf.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@
4848
Code
4949
translate(svm_rbf(mode = "regression") %>% set_engine(NULL))
5050
Condition
51-
Error in `if (object$engine == "liquidSVM") ...`:
52-
! argument is of length zero
51+
Error in `translate.default()`:
52+
! Please set an engine.
5353

tests/testthat/test-nearest_neighbor.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ test_that('updating', {
88

99
test_that('bad input', {
1010
expect_snapshot(error = TRUE, nearest_neighbor(mode = "reallyunknown"))
11-
expect_snapshot(error = TRUE, nearest_neighbor() %>% set_engine( NULL))
1211
})
1312

1413
test_that('check_args() works', {
1514
skip_if_not_installed("kknn")
1615

1716
hpc <- hpc_data[1:150, c(2:5, 8)]
18-
17+
1918
expect_snapshot(
2019
error = TRUE,
2120
{
22-
spec <- nearest_neighbor(neighbors = -1) %>%
21+
spec <- nearest_neighbor(neighbors = -1) %>%
2322
set_engine("kknn") %>%
2423
set_mode("classification")
2524
fit(spec, class ~ ., hpc)
@@ -28,7 +27,7 @@ test_that('check_args() works', {
2827
expect_snapshot(
2928
error = TRUE,
3029
{
31-
spec <- nearest_neighbor(weight_func = 2) %>%
30+
spec <- nearest_neighbor(weight_func = 2) %>%
3231
set_engine("kknn") %>%
3332
set_mode("classification")
3433
fit(spec, class ~ ., hpc)

tests/testthat/test-rand_forest.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test_that('updating', {
88
})
99

1010
test_that('bad input', {
11-
expect_snapshot(error = TRUE, translate(rand_forest(mode = "classification") %>% set_engine(NULL)))
11+
expect_snapshot(res <- translate(rand_forest(mode = "classification") %>% set_engine(NULL)))
1212
expect_snapshot(error = TRUE, rand_forest(mode = "time series"))
1313
expect_snapshot(error = TRUE, translate(rand_forest(mode = "classification") %>% set_engine("wat?")))
1414
expect_snapshot(error = TRUE, translate(rand_forest(mode = "classification", ytest = 2)))
@@ -17,4 +17,4 @@ test_that('bad input', {
1717
test_that("check_args() works", {
1818
# Here for completeness, no checking is done
1919
expect_true(TRUE)
20-
})
20+
})

tests/testthat/test-surv_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test_that('bad input', {
1313

1414
expect_snapshot(error = TRUE, surv_reg(mode = ", classification"))
1515
expect_snapshot(error = TRUE, translate(surv_reg() %>% set_engine("wat")))
16-
expect_snapshot(error = TRUE, translate(surv_reg() %>% set_engine(NULL)))
16+
expect_snapshot(res <- translate(surv_reg() %>% set_engine(NULL)))
1717
})
1818

1919
test_that("deprecation warning", {

0 commit comments

Comments
 (0)