Learn R Programming

bigstatsr (version 0.6.2)

FBM.code256-class: 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(), create_bk = TRUE)

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 rep(NA_real_, 256) and then replace the values which are of interest for you.

init

Either a single value (e.g. 0) or as many value as the number of elements of the FBM. Default doesn't initialize the matrix.

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

Create a backingfile (the default) or use an existing one (which should be named by the backingfile parameter and have an extension ".bk"). For example, this could be used to convert a filebacked big.matrix from package bigmemory to a FBM.

x

A FBM.

Examples

Run this code
# NOT RUN {
X <- FBM(10, 10, type = "raw")
X[] <- sample(as.raw(0:3), size = length(X), replace = TRUE)
X[]

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[]

# Copy the FBM with another code
X.code3 <- X.code$copy(code = rnorm(256))
stopifnot(all.equal(X.code$code256, code))

# }

Run the code above in your browser using DataLab