Skip to content

Commit 2b8f56e

Browse files
committed
don't use glmnet in sparsevctrs tests
1 parent fddd590 commit 2b8f56e

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

tests/testthat/_snaps/sparsevctrs.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
# to_sparse_data_frame() is used correctly
22

33
Code
4-
fit_xy(lm_spec, x = mtcars[, -1], y = mtcars[, 1])
4+
fit_xy(spec, x = mtcars[, -1], y = mtcars[, 1])
55
Condition
66
Error in `to_sparse_data_frame()`:
77
! x is not sparse
88

99
---
1010

1111
Code
12-
fit_xy(lm_spec, x = hotel_data[, -1], y = hotel_data[, 1])
12+
fit_xy(spec, x = hotel_data[, -1], y = hotel_data[, 1])
1313
Condition
1414
Error in `to_sparse_data_frame()`:
1515
! x is spare, and sparse is not allowed
1616

1717
---
1818

1919
Code
20-
fit_xy(lm_spec, x = hotel_data[, -1], y = hotel_data[, 1])
20+
fit_xy(spec, x = hotel_data[, -1], y = hotel_data[, 1])
2121
Condition
2222
Error in `to_sparse_data_frame()`:
2323
! x is spare, and sparse is allowed
2424

2525
# maybe_sparse_matrix() is used correctly
2626

2727
Code
28-
fit_xy(lm_spec, x = hotel_data[, -1], y = hotel_data[, 1])
28+
fit_xy(spec, x = hotel_data[, -1], y = hotel_data[, 1])
2929
Condition
3030
Error in `maybe_sparse_matrix()`:
3131
! sparse vectors detected
3232

3333
---
3434

3535
Code
36-
fit_xy(lm_spec, x = mtcars[, -1], y = mtcars[, 1])
36+
fit_xy(spec, x = mtcars[, -1], y = mtcars[, 1])
3737
Condition
3838
Error in `maybe_sparse_matrix()`:
3939
! no sparse vectors detected
4040

4141
---
4242

4343
Code
44-
fit_xy(lm_spec, x = as.data.frame(mtcars)[, -1], y = as.data.frame(mtcars)[, 1])
44+
fit_xy(spec, x = as.data.frame(mtcars)[, -1], y = as.data.frame(mtcars)[, 1])
4545
Condition
4646
Error in `maybe_sparse_matrix()`:
4747
! no sparse vectors detected
4848

4949
---
5050

5151
Code
52-
fit_xy(lm_spec, x = tibble::as_tibble(mtcars)[, -1], y = tibble::as_tibble(
53-
mtcars)[, 1])
52+
fit_xy(spec, x = tibble::as_tibble(mtcars)[, -1], y = tibble::as_tibble(mtcars)[,
53+
1])
5454
Condition
5555
Error in `maybe_sparse_matrix()`:
5656
! no sparse vectors detected

tests/testthat/test-sparsevctrs.R

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
test_that("sparse matrices can be passed to `fit_xy()", {
2+
skip_if_not_installed("LiblineaR")
3+
24
hotel_data <- sparse_hotel_rates()
35

4-
lm_spec <- linear_reg(penalty = 0) %>%
5-
set_engine("glmnet")
6+
spec <- svm_linear() %>%
7+
set_mode("regression") %>%
8+
set_engine("LiblineaR")
69

710
expect_no_error(
8-
lm_fit <- fit_xy(lm_spec, x = hotel_data[, -1], y = hotel_data[, 1])
11+
lm_fit <- fit_xy(spec, x = hotel_data[, -1], y = hotel_data[, 1])
912
)
1013
})
1114

1215
test_that("to_sparse_data_frame() is used correctly", {
16+
skip_if_not_installed("LiblineaR")
17+
1318
local_mocked_bindings(
1419
to_sparse_data_frame = function(x, object) {
1520
if (methods::is(x, "sparseMatrix")) {
@@ -25,28 +30,31 @@ test_that("to_sparse_data_frame() is used correctly", {
2530

2631
hotel_data <- sparse_hotel_rates()
2732

28-
lm_spec <- linear_reg(penalty = 0) %>%
33+
spec <- linear_reg() %>%
2934
set_engine("lm")
3035

3136
expect_snapshot(
3237
error = TRUE,
33-
fit_xy(lm_spec, x = mtcars[, -1], y = mtcars[, 1])
38+
fit_xy(spec, x = mtcars[, -1], y = mtcars[, 1])
3439
)
3540
expect_snapshot(
3641
error = TRUE,
37-
fit_xy(lm_spec, x = hotel_data[, -1], y = hotel_data[, 1])
42+
fit_xy(spec, x = hotel_data[, -1], y = hotel_data[, 1])
3843
)
3944

40-
lm_spec <- linear_reg(penalty = 0) %>%
41-
set_engine("glmnet")
45+
spec <- svm_linear() %>%
46+
set_mode("regression") %>%
47+
set_engine("LiblineaR")
4248

4349
expect_snapshot(
4450
error = TRUE,
45-
fit_xy(lm_spec, x = hotel_data[, -1], y = hotel_data[, 1])
51+
fit_xy(spec, x = hotel_data[, -1], y = hotel_data[, 1])
4652
)
4753
})
4854

4955
test_that("maybe_sparse_matrix() is used correctly", {
56+
skip_if_not_installed("LiblineaR")
57+
5058
local_mocked_bindings(
5159
maybe_sparse_matrix = function(x) {
5260
if (any(vapply(x, sparsevctrs::is_sparse_vector, logical(1)))) {
@@ -59,23 +67,24 @@ test_that("maybe_sparse_matrix() is used correctly", {
5967

6068
hotel_data <- sparse_hotel_rates()
6169

62-
lm_spec <- linear_reg(penalty = 0) %>%
63-
set_engine("glmnet")
70+
spec <- svm_linear() %>%
71+
set_mode("regression") %>%
72+
set_engine("LiblineaR")
6473

6574
expect_snapshot(
6675
error = TRUE,
67-
fit_xy(lm_spec, x = hotel_data[, -1], y = hotel_data[, 1])
76+
fit_xy(spec, x = hotel_data[, -1], y = hotel_data[, 1])
6877
)
6978
expect_snapshot(
7079
error = TRUE,
71-
fit_xy(lm_spec, x = mtcars[, -1], y = mtcars[, 1])
80+
fit_xy(spec, x = mtcars[, -1], y = mtcars[, 1])
7281
)
7382
expect_snapshot(
7483
error = TRUE,
75-
fit_xy(lm_spec, x = as.data.frame(mtcars)[, -1], y = as.data.frame(mtcars)[, 1])
84+
fit_xy(spec, x = as.data.frame(mtcars)[, -1], y = as.data.frame(mtcars)[, 1])
7685
)
7786
expect_snapshot(
7887
error = TRUE,
79-
fit_xy(lm_spec, x = tibble::as_tibble(mtcars)[, -1], y = tibble::as_tibble(mtcars)[, 1])
88+
fit_xy(spec, x = tibble::as_tibble(mtcars)[, -1], y = tibble::as_tibble(mtcars)[, 1])
8089
)
8190
})

0 commit comments

Comments
 (0)