Skip to content

Commit aef20ae

Browse files
committed
better checks for tune install
1 parent 5f0225e commit aef20ae

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

tests/testthat/helpers.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11

22
# In some cases, the test value needs to be wrapped in an empty
33
# environment. If arguments are set in the model specification
4-
# (as opposed to being set by a `translate` function), they will
5-
# need this wrapper.
4+
# (as opposed to being set by a `translate` function), they will
5+
# need this wrapper.
66

77
new_empty_quosure <- function(expr) {
88
new_quosure(expr, env = empty_env())
99
}
1010

11+
tune_check <- function() {
12+
if (rlang::is_installed("tune")) {
13+
res <- utils::packageVersion("tune") <= "0.1.6"
14+
} else {
15+
res <- TRUE
16+
}
17+
res
18+
}
19+

tests/testthat/test_extract.R

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ context("model extraction")
44
# ------------------------------------------------------------------------------
55

66
test_that('extract', {
7-
skip_if(
8-
rlang::is_installed("tune") |
9-
utils::packageVersion("tune") <= "0.1.6"
10-
)
7+
skip_if(tune_check())
118

129
x <- linear_reg() %>% set_engine("lm") %>% fit(mpg ~ ., data = mtcars)
1310
x_no_spec <- x
@@ -26,10 +23,7 @@ test_that('extract', {
2623

2724
test_that('extract parameter set from model with no parameters', {
2825
skip_on_covr()
29-
skip_if(
30-
rlang::is_installed("tune") |
31-
utils::packageVersion("tune") <= "0.1.6"
32-
)
26+
skip_if(tune_check())
3327

3428
lm_model <- linear_reg() %>% set_engine("lm")
3529

@@ -40,10 +34,7 @@ test_that('extract parameter set from model with no parameters', {
4034

4135
test_that('extract parameter set from model with main and engine parameters', {
4236
skip_on_covr()
43-
skip_if(
44-
rlang::is_installed("tune") |
45-
utils::packageVersion("tune") <= "0.1.6"
46-
)
37+
skip_if(tune_check())
4738

4839
bst_model <-
4940
boost_tree(mode = "classification", trees = hardhat::tune("funky name \n")) %>%
@@ -68,10 +59,7 @@ test_that('extract parameter set from model with main and engine parameters', {
6859

6960
test_that('extract single parameter from model with no parameters', {
7061
skip_on_covr()
71-
skip_if(
72-
rlang::is_installed("tune") |
73-
utils::packageVersion("tune") <= "0.1.6"
74-
)
62+
skip_if(tune_check())
7563

7664
lm_model <- linear_reg() %>% set_engine("lm")
7765

@@ -82,10 +70,7 @@ test_that('extract single parameter from model with no parameters', {
8270

8371
test_that('extract single parameter from model with main and engine parameters', {
8472
skip_on_covr()
85-
skip_if(
86-
rlang::is_installed("tune") |
87-
utils::packageVersion("tune") <= "0.1.6"
88-
)
73+
skip_if(tune_check())
8974

9075
bst_model <-
9176
boost_tree(mode = "classification", trees = hardhat::tune("funky name \n")) %>%

0 commit comments

Comments
 (0)