"filematrix"
)filematrix
is a class for working with very large matrices
stored in files, not held in computer memory.
It is intended as a simple, efficient solution to handling big numeric data
(i.e., datasets larger than memory capacity) in R.
A new filematrix can be created with fm.create
.
It can be created from an existing R matrix
with fm.create.from.matrix
.
A text file with a matrix can be scanned and converted into a filematrix
with fm.create.from.text.file
.
An existing filematrix can be opened for read/write access
with fm.open
or loaded fully in memory
with fm.load
.
A filematrix can be handled as an ordinary matrix in R.
It can be read from and written to via usual indexing
with possible omission of indices.
For example: fm[1:3,2:4]
and fm[,2:4]
.
The values can also be accessed as a vector
with single indexing.
For example: fm[3:7]
and fm[4:7] = 1:4
.
A whole filematrix can be read memory as an ordinary R matrix
with as.matrix
function or empty indexing fm[]
.
The dimensions of filematrix can be obtained via dim
,
nrow
and ncol
functions and
modified with dim
function.
For example: dim(fm)
and dim(fm) = c(10,100)
.
The number of elements in filematrix is returned by length
function.
A filematrix can have row and column names.
They can be accessed using the standard functions
rownames
, colnames
, and dimnames
.
A filematrix can be closed after use with close
command.
Note, however, that there is no risk of losing modifications
to a filematrix if an object is not closed,
as all changes are written to disk without delay.
# S3 method for filematrix
[(x,i,j)
# S3 method for filematrix
[(x,i,j) <- value# S4 method for filematrix
as.matrix(x)
# S4 method for filematrix
dim(x)
# S4 method for filematrix
dim(x) <- value
# S4 method for filematrix
length(x)
# S4 method for filematrix
rownames(x)
# S4 method for filematrix
rownames(x) <- value
# S4 method for filematrix
colnames(x)
# S4 method for filematrix
colnames(x) <- value
# S4 method for filematrix
dimnames(x)
# S4 method for filematrix
dimnames(x) <- value
A filematrix object (filematrix
).
Row/column indices specifying elements to extract or replace.
A new value to replace the indexed element(s).
length
function returns the number of elements in the filematrix.
Functions colnames
, rownames
, and dimnames
return
the same values as their counterparts for the regular R matrices.
isOpen
Returns TRUE
is the filematrix is open.
readAll()
:Return the whole matrix.
Same as fm[]
or as.matrix(fm)
writeAll(value)
:Fill in the whole matrix.
Same as fm[] = value
readSubCol(i, j, num)
:Read num
values in column j
starting with row i
.
Same as fm[i:(i+num-1), j]
writeSubCol(i, j, value)
:Write values in the column j
starting with row i
.
Same as fm[i:(i+length(value)-1), j] = value
readCols(start, num)
:Read num
columns starting with column start
.
Same as fm[, start:(start+num-1)]
writeCols(start, value)
:Write columns starting with column start
.
Same as fm[, start:(start+ncol(value)-1)] = value
readSeq(start, len)
:Read len
values from the matrix starting with
start
-th value.
Same as fm[start:(start+len-1)]
writeSeq(start, value)
:Write values in the matrix starting with start
-th value.
Same as fm[start:(start+length(value)-1)] = value
appendColumns(mat)
Increases filematrix by adding columns to the right side of the matrix.
Matrix mat
must have the same number of rows.
Same as fm = cbind(fm, mat)
for ordinary matrices.
For function creating and opening file matrices see
fm.create
.
Run browseVignettes("filematrix")
for the list of vignettes.