FBM.code256-class {bigstatsr} | R Documentation |
Class FBM.code256
Description
A reference class for storing and accessing up to 256 arbitrary different
values using a Filebacked Big Matrix of type unsigned char
. Compared to a
Filebacked Big Matrix, it adds a slot code
which is used as
a lookup table of size 256.
Usage
FBM.code256(
nrow,
ncol,
code = rep(NA_real_, 256),
init = NULL,
backingfile = tempfile(tmpdir = getOption("FBM.dir")),
create_bk = TRUE,
is_read_only = FALSE
)
add_code256(x, code)
Arguments
nrow |
Number of rows. |
ncol |
Number of columns. |
code |
A numeric vector (of length 256).
You should construct it with |
init |
Either a single value (e.g. |
backingfile |
Path to the file storing the Big Matrix on disk. An extension ".bk" will be automatically added. Default stores in the temporary directory. |
create_bk |
Whether to create a backingfile (the default) or use an
existing one (which should be named by the |
is_read_only |
Whether the FBM is read-only? Default is |
x |
A FBM. |
Examples
X <- FBM(10, 10, type = "raw")
X[] <- sample(as.raw(0:3), size = length(X), replace = TRUE)
X[]
# From an FBM of type 'raw' ('unsigned char')
code <- rep(NA_real_, 256)
code[1:3] <- c(1, 3, 5)
X.code <- add_code256(X, code)
X.code[]
# Or directly
X.code2 <- FBM.code256(10, 10, code, init = sample(as.raw(0:3), 100, TRUE))
X.code2[]
# Get a new FBM.code256 object with another code (but same underlying data)
X.code3 <- X.code$copy(code = rnorm(256))
all.equal(X.code$code256, code)