lvec: Create memory mapped vector

View source: R/lvec.R

lvecR Documentation

Create memory mapped vector

Description

The data in these vectors are stored on disk (partially buffered for speed) allowing one to work with more data than fits into available memory.

Usage

lvec(
  size,
  type = c("numeric", "integer", "logical", "character"),
  strlen = NULL
)

Arguments

size

the size of the vector

type

the type of the vector. Should be one of the following value: "numeric", "integer", "logical" or "character". The types will create vectors corresponding to the corresponding R types.

strlen

in case of a vector of type "character" the maximum length of the strings should also be specified using strlen.

Details

The minimum value of strlen is two. When a value smaller than that is given it is automatically set to two. This is because a minimum of two bytes is necessary to also store missing values correctly.

Value

Returns an object of type lvec. Elements of this vector are stored on file (partially buffered in memory for speed) allowing one to work with more data than fits into memory.

Examples

# create an integer vector of length 100
x <- lvec(100, type = "integer")
# Get the first 10 values; values are initialised to 0 by default
lget(x, 1:10)
# Set the first 10 values to 11:20
lset(x, 1:10, 11:20)

# set maximum length of the string to 1, strings longer than that get
# truncated. However, minimum value of strlen is 2. 
x <- lvec(10, type = "character", strlen = 1)
lset(x, 1:3, c("a", "foo", NA))
lget(x, 1:3)


djvanderlaan/lvec documentation built on Oct. 26, 2022, 11:43 a.m.