FileVector {R.huge} | R Documentation |
Class representing a persistent vector stored on file
Description
Package: R.huge
Class FileVector
Object
~~|
~~+--
AbstractFileArray
~~~~~~~|
~~~~~~~+--
FileVector
Directly known subclasses:
FileByteVector, FileDoubleVector, FileFloatVector, FileIntegerVector, FileShortVector
public static class FileVector
extends AbstractFileArray
Usage
FileVector(..., length=NULL, names=NULL)
Arguments
... |
Arguments passed to |
length |
The number of elements in the vector. |
names |
Optional element names. |
Details
The purpose of this class is to be able to work with large vectors in R without being limited by the amount of memory available. Data is kept on the file system and elements are read and written whenever queried.
For more details, AbstractFileArray
.
Fields and Methods
Methods:
[ | - | |
[<- | - | |
names | Gets the element names of a file vector. | |
Methods inherited from AbstractFileArray:
as.character, as.vector, clone, close, delete, dim, dimnames, finalize, flush, getBasename, getBytesPerCell, getCloneNumber, getComments, getDataOffset, getDimensionOrder, getExtension, getFileSize, getName, getPath, getPathname, getSizeOfComments, getSizeOfData, getStorageMode, isOpen, length, open, readAllValues, readContiguousValues, readHeader, readValues, setComments, writeAllValues, writeEmptyData, writeHeader, writeHeaderComments, writeValues
Methods inherited from Object:
$, $<-, [[, [[<-, as.character, attach, attachLocally, clearCache, clearLookupCache, clone, detach, equals, extend, finalize, getEnvironment, getFieldModifier, getFieldModifiers, getFields, getInstantiationTime, getStaticInstance, hasField, hashCode, ll, load, names, objectSize, print, save
Supported data types
The following subclasses implement support for various data types:
-
FileByteVector
(1 byte per element), -
FileShortVector
(2 bytes per element), -
FileIntegerVector
(4 bytes per element), -
FileFloatVector
(4 bytes per element), and -
FileDoubleVector
(8 bytes per element).
Author(s)
Henrik Bengtsson
Examples
library("R.utils")
verbose <- Arguments$getVerbose(TRUE)
pathname <- "example.Rvector"
if (isFile(pathname)) {
file.remove(pathname)
if (isFile(pathname)) {
stop("File not deleted: ", pathname)
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Create a new file vector
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
verbose && enter(verbose, "Creating new vector")
# The length of the vector
length <- 1e6
X <- FileDoubleVector(pathname, length=length)
verbose && exit(verbose)
print(X)
verbose && enter(verbose, "Filling it with data")
idxs <- c(1:4,7:10)
x <- 1:length(idxs)
writeValues(X, indices=idxs, values=x)
verbose && exit(verbose)
verbose && enter(verbose, "Getting data again")
y <- readValues(X, indices=idxs)
verbose && exit(verbose)
stopifnot(all.equal(x,y))
verbose && enter(verbose, "Getting and setting data using [i,j]")
print(X[1:20])
i <- 13:15
X[i] <- 99:98
print(X[1:20])
verbose && exit(verbose)
delete(X)
rm(X)