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.
FBM.code256( nrow, ncol, code = rep(NA_real_, 256), init = NULL, backingfile = tempfile(), create_bk = TRUE, is_read_only = FALSE ) add_code256(x, code)
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. |
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 03 00 01 02 01 02 03 01 03 03 #> [2,] 01 03 00 01 00 03 01 02 01 03 #> [3,] 01 03 00 00 01 01 03 00 01 03 #> [4,] 03 01 02 02 03 00 01 00 00 02 #> [5,] 03 01 02 03 00 01 00 00 02 00 #> [6,] 01 03 03 01 03 02 00 00 02 03 #> [7,] 01 01 02 02 00 01 00 02 00 02 #> [8,] 02 00 01 00 03 03 02 00 02 00 #> [9,] 03 00 01 00 00 01 03 01 00 01 #> [10,] 00 00 02 03 00 01 02 00 03 02# 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[]#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] NA 1 3 5 3 5 NA 3 NA NA #> [2,] 3 NA 1 3 1 NA 3 5 3 NA #> [3,] 3 NA 1 1 3 3 NA 1 3 NA #> [4,] NA 3 5 5 NA 1 3 1 1 5 #> [5,] NA 3 5 NA 1 3 1 1 5 1 #> [6,] 3 NA NA 3 NA 5 1 1 5 NA #> [7,] 3 3 5 5 1 3 1 5 1 5 #> [8,] 5 1 3 1 NA NA 5 1 5 1 #> [9,] NA 1 3 1 1 3 NA 3 1 3 #> [10,] 1 1 5 NA 1 3 5 1 NA 5#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 1 3 3 NA 3 5 1 NA 5 3 #> [2,] 5 5 3 NA 3 NA 5 5 1 NA #> [3,] 1 NA 1 1 NA NA 3 1 1 3 #> [4,] 5 NA 1 5 1 5 1 1 3 1 #> [5,] 5 1 3 NA NA 1 3 5 5 3 #> [6,] 5 5 NA NA 1 1 5 5 5 NA #> [7,] 3 1 1 NA NA 3 3 1 5 1 #> [8,] NA 3 NA 1 NA 1 1 NA 3 NA #> [9,] 3 NA NA 3 5 3 5 NA 3 5 #> [10,] NA NA 1 5 3 NA NA 3 1 3# 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)#> [1] TRUE