Learn R Programming

bigstatsr (version 0.6.2)

FBM-class: Class FBM

Description

A reference class for storing and accessing matrix-like data stored in files on disk. This is very similar to Filebacked Big Matrices provided by the bigmemory package. Yet, the implementation is lighter.

Convert a matrix (or a data frame) to an FBM.

Usage

FBM(nrow, ncol, type = c("double", "integer", "unsigned short",
  "unsigned char", "raw"), init = NULL, backingfile = tempfile(),
  create_bk = TRUE)

as_FBM(x, type = c("double", "integer", "unsigned short", "unsigned char", "raw"), backingfile = tempfile())

Arguments

nrow

Number of rows.

ncol

Number of columns.

type

Type of the Filebacked Big Matrix (default is double). Either

  • "double"

  • "integer"

  • "unsigned short": can store integer values from 0 to 65535. It has vocation to become the basis for a FBM.code65536 class for accessing strings.

  • "raw" or "unsigned char": can store integer values from 0 to 255. It is the basis for the FBM.code256 class for accessing 256 arbitrary different numeric values. It is used in package bigsnpr.

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 matrix or an data frame (2-dimensional data).

Details

An FBM object has many field:

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

  • $extptr: use $address instead

  • $nrow

  • $ncol

  • $type

  • $backingfile or $bk: File with extension 'bk' that stores the numeric data of the FBM

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

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

And two methods:

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

  • add_columns(<ncol_add>): Add some columns to the FBM by appending the backingfile with some data. Returns the FBM invisibly.

See Also

big_copy

Examples

Run this code
# NOT RUN {
X <- FBM(10, 10)
typeof(X)
X[] <- rnorm(length(X))
X[, 1:6]
X[] <- 1:100
X[, 1]
X[1, ]  # not recommended for large matrices
X[, -1]
X[, c(TRUE, FALSE)]
X[cbind(1:10, 1:10)] <- NA_real_
X[]

X <- FBM(150, 5)
X[] <- iris   ## you can replace with a df (factors -> integers)
X2 <- as_FBM(iris)
identical(X[], X2[])
# }

Run the code above in your browser using DataLab