SFBM-class: Class SFBM

SFBM-classR Documentation

Class SFBM


A reference class for storing and accessing sparse matrix-like data stored in files on disk.

Convert a 'dgCMatrix' or 'dsCMatrix' to an SFBM.


as_SFBM(spmat, backingfile = tempfile(), compact = FALSE)



A 'dgCMatrix' (non-symmetric sparse matrix of type 'double') or 'dsCMatrix' (symmetric sparse matrix of type 'double').


Path to file where to store data. Extension .sbk is automatically added.


Whether to use a compact format? Default is FALSE. This is useful when non-zero values in columns are contiguous (or almost).


An object of class SFBM has many fields:

  • ⁠$address⁠: address of the external pointer containing the underlying C++ object to be used as a ⁠XPtr<SFBM>⁠ in C++ code

  • ⁠$extptr⁠: (internal) use ⁠$address⁠ instead

  • ⁠$nrow⁠: number of rows

  • ⁠$ncol⁠: number of columns

  • ⁠$nval⁠: number of non-zero values

  • ⁠$p⁠: vector of column positions

  • ⁠$backingfile⁠ or ⁠$sbk⁠: File with extension 'sbk' that stores the data of the SFBM

  • ⁠$rds⁠: 'rds' file (that may not exist) corresponding to the 'sbk' file

  • ⁠$is_saved⁠: whether this object is stored in ⁠$rds⁠?

And some methods:

  • ⁠$save()⁠: Save the SFBM object in ⁠$rds⁠. Returns the SFBM.

  • ⁠$add_columns()⁠: Add new columns from a 'dgCMatrix' or a 'dsCMatrix'.

  • ⁠$dense_acc()⁠: Equivalent to as.matrix(.[ind_row, ind_col]). Use with caution; ind_row and ind_col must be positive indices within range.


The new SFBM.


spmat2 <- Matrix::Diagonal(4, 0:3)
spmat2[4, 2] <- 5
spmat2[1, 4] <- 6
spmat2[3, 4] <- 7

# Stores all (i, x) for x != 0
(X2 <- as_SFBM(spmat2))
matrix(readBin(X2$sbk, what = double(), n = 100), 2)

# Stores only x, but all (even the zero ones) from first to last being not 0
(X3 <- as_SFBM(spmat2, compact = TRUE))
readBin(X3$sbk, what = double(), n = 100)

bigsparser documentation built on June 22, 2024, 10:03 a.m.