Skip to content

Commit 4584a9b

Browse files
committed
let fit_xy() take dgCMatrix input
1 parent 8880aff commit 4584a9b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

R/convert_data.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,11 @@ maybe_matrix <- function(x) {
374374
"converted to numeric matrix: {non_num_cols}.")
375375
rlang::abort(msg)
376376
}
377-
x <- as.matrix(x)
377+
if (any(vapply(x, sparsevctrs::is_sparse_vector, logical(1)))) {
378+
x <- sparsevctrs::coerce_to_sparse_matrix(x)
379+
} else {
380+
x <- as.matrix(x)
381+
}
378382
}
379383
# leave alone if matrix or sparse matrix
380384
x

R/fit.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ fit_xy.model_spec <-
275275
}
276276
}
277277

278+
if (allow_sparse(object) && methods::is(x, "sparseMatrix")) {
279+
x <- sparsevctrs::coerce_to_sparse_data_frame(x)
280+
}
281+
278282
cl <- match.call(expand.dots = TRUE)
279283
eval_env <- rlang::env()
280284
eval_env$x <- x
@@ -387,7 +391,7 @@ inher <- function(x, cls, cl) {
387391

388392
check_interface <- function(formula, data, cl, model) {
389393
inher(formula, "formula", cl)
390-
inher(data, c("data.frame", "tbl_spark"), cl)
394+
inher(data, c("data.frame", "dgCMatrix", "tbl_spark"), cl)
391395

392396
# Determine the `fit()` interface
393397
form_interface <- !is.null(formula) & !is.null(data)

0 commit comments

Comments
 (0)