Skip to content

Commit 124f925

Browse files
committed
trigger warning in to_sparse_data_frame()
1 parent ae90e84 commit 124f925

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

R/sparsevctrs.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ to_sparse_data_frame <- function(x, object) {
77
"!" = "{.arg x} is a sparse matrix, but model doesn't accept that.",
88
"i" = "Converted {.arg x} to data.frame."
99
))
10-
x <- as.data.frame(x)
10+
x <- as.data.frame(as.matrix(x))
1111
}
1212
}
1313
x

tests/testthat/_snaps/sparsevctrs.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# sparse matrices can be passed to `fit_xy()
2+
3+
Code
4+
lm_fit <- fit_xy(spec, x = hotel_data[1:100, -1], y = hotel_data[1:100, 1])
5+
Condition
6+
Warning:
7+
! `x` is a sparse matrix, but model doesn't accept that.
8+
i Converted `x` to data.frame.
9+
110
# to_sparse_data_frame() is used correctly
211

312
Code

tests/testthat/test-sparsevctrs.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ test_that("sparse matrices can be passed to `fit_xy()", {
1010
expect_no_error(
1111
lm_fit <- fit_xy(spec, x = hotel_data[, -1], y = hotel_data[, 1])
1212
)
13+
14+
spec <- linear_reg() %>%
15+
set_mode("regression") %>%
16+
set_engine("lm")
17+
18+
expect_snapshot(
19+
lm_fit <- fit_xy(spec, x = hotel_data[1:100, -1], y = hotel_data[1:100, 1])
20+
)
1321
})
1422

1523
test_that("to_sparse_data_frame() is used correctly", {

0 commit comments

Comments
 (0)