File tree Expand file tree Collapse file tree 3 files changed +25
-16
lines changed Expand file tree Collapse file tree 3 files changed +25
-16
lines changed Original file line number Diff line number Diff line change @@ -374,16 +374,21 @@ maybe_matrix <- function(x) {
374
374
" converted to numeric matrix: {non_num_cols}." )
375
375
rlang :: abort(msg )
376
376
}
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
- }
377
+ x <- maybe_sparse_matrix(x )
382
378
}
383
379
# leave alone if matrix or sparse matrix
384
380
x
385
381
}
386
382
383
+ maybe_sparse_matrix <- function (x ) {
384
+ if (any(vapply(x , sparsevctrs :: is_sparse_vector , logical (1 )))) {
385
+ res <- sparsevctrs :: coerce_to_sparse_matrix(x )
386
+ } else {
387
+ res <- as.matrix(x )
388
+ }
389
+ res
390
+ }
391
+
387
392
# ' @rdname maybe_matrix
388
393
# ' @export
389
394
maybe_data_frame <- function (x ) {
Original file line number Diff line number Diff line change @@ -275,17 +275,7 @@ fit_xy.model_spec <-
275
275
}
276
276
}
277
277
278
- if (methods :: is(x , " sparseMatrix" )) {
279
- if (allow_sparse(object )) {
280
- x <- sparsevctrs :: coerce_to_sparse_data_frame(x )
281
- } else {
282
- cli :: cli_warn(c(
283
- " !" = " {.arg x} is a sparse matrix, but model doesn't accept that." ,
284
- " i" = " Converted {.arg x} to data.frame."
285
- ))
286
- x <- as.data.frame(x )
287
- }
288
- }
278
+ x <- to_sparse_data_frame(x , object )
289
279
290
280
cl <- match.call(expand.dots = TRUE )
291
281
eval_env <- rlang :: env()
Original file line number Diff line number Diff line change
1
+ to_sparse_data_frame <- function (x , object ) {
2
+ if (methods :: is(x , " sparseMatrix" )) {
3
+ if (allow_sparse(object )) {
4
+ x <- sparsevctrs :: coerce_to_sparse_data_frame(x )
5
+ } else {
6
+ cli :: cli_warn(c(
7
+ " !" = " {.arg x} is a sparse matrix, but model doesn't accept that." ,
8
+ " i" = " Converted {.arg x} to data.frame."
9
+ ))
10
+ x <- as.data.frame(x )
11
+ }
12
+ }
13
+ x
14
+ }
You can’t perform that action at this time.
0 commit comments