BPCells matrices can be interconverted with Matrix package dgCMatrix sparse matrices, as well as base R dense matrices (though this may result in high memory usage for large matrices)
Examples
mat <- get_demo_mat()[1:2, 1:2]
mat
#> 2 x 2 IterableMatrix object with class MatrixSubset
#>
#> Row names: ENSG00000272602, ENSG00000250312
#> Col names: TTTAGCAAGGTAGCTT-1, AGCCGGTTCCGGAACC-1
#>
#> Data type: uint32_t
#> Storage order: column major
#>
#> Queued Operations:
#> 1. Load compressed matrix from directory /home/imman/.local/share/R/BPCells/demo_data/demo_mat_filtered_subsetted
#> 2. Select rows: 1, 2 and cols: 1, 2
#######################################################################
## as(bpcells_mat, "dgCMatrix") example
#######################################################################
mat_dgc <- as(mat, "dgCMatrix")
mat_dgc
#> 2 x 2 sparse Matrix of class "dgCMatrix"
#> TTTAGCAAGGTAGCTT-1 AGCCGGTTCCGGAACC-1
#> ENSG00000272602 1 .
#> ENSG00000250312 . .
## as.matrix(bpcells_mat) example
as.matrix(mat)
#> TTTAGCAAGGTAGCTT-1 AGCCGGTTCCGGAACC-1
#> ENSG00000272602 1 0
#> ENSG00000250312 0 0
## Alternatively, can also use function as()
as(mat, "matrix")
#> TTTAGCAAGGTAGCTT-1 AGCCGGTTCCGGAACC-1
#> ENSG00000272602 1 0
#> ENSG00000250312 0 0
#######################################################################
## as(dgc_mat, "IterableMatrix") example
#######################################################################
as(mat_dgc, "IterableMatrix")
#> 2 x 2 IterableMatrix object with class Iterable_dgCMatrix_wrapper
#>
#> Row names: ENSG00000272602, ENSG00000250312
#> Col names: TTTAGCAAGGTAGCTT-1, AGCCGGTTCCGGAACC-1
#>
#> Data type: double
#> Storage order: column major
#>
#> Queued Operations:
#> 1. Load dgCMatrix from memory