Learn R Programming

dipsaus (version 0.3.1)

fastmap2: A Wrapper for fastmap::fastmap

Description

fastmap provides a key-value store where the keys are strings and the values are any R objects. It differs from normal environment that fastmap avoids memory leak. fastmap2 is a wrapper for fastmap, which provides several generic functions such that it has similar behaviors to lists or environments

Usage

fastmap2(missing_default = NULL)

# S3 method for fastmap2 [[(x, name)

# S3 method for fastmap2 $(x, name)

# S3 method for fastmap2 [[(x, name) <- value

# S3 method for fastmap2 $(x, name) <- value

# S3 method for fastmap2 [(x, i, j = NULL, ...)

# S3 method for fastmap2 [(x, i, j = NULL, ...) <- value

# S3 method for fastmap2 names(x)

# S3 method for fastmap2 print(x, ...)

# S3 method for fastmap2 length(x)

# S3 method for fastmap2 as.list(x, recursive = FALSE, sorted = FALSE, ...)

Value

A list of 'fastmap2' instance

Arguments

missing_default

passed to fastmap::fastmap

x

a 'fastmap2' object

name

name, or key of the value

value

any R object

i, j

vector of names

...

passed to other methods

recursive

whether to recursively apply as.list

sorted

whether to sort names; default is false

Examples

Run this code

## --------------------------- Basic Usage --------------------------
map <- fastmap2()
map$a = 1
map$b = 2
print(map)

map[c('a', 'b')]
# Alternative way
map['a', 'b']

map[c('c', 'd')] <- 3:4
# or
map['e', 'f'] <- 5:6

# The order is not guaranteed, unless sort=TRUE
as.list(map)
as.list(map, sort=TRUE)

names(map)
length(map)

## ----------------------- NULL value handles -----------------------
map$b <- NULL
names(map)   # 'b' still exists!
as.list(map) # 'b' is NULL, but still there

# to remove 'b', you have to use `@remove` method
map$`@remove`('b')

## ---------------- Native fastmap::fastmap methods -----------------

# whether map has 'a'
map$`@has`('a')

# Remove a name from list
map$`@remove`('a')

# remove all from list
map$`@reset`()
print(map)

Run the code above in your browser using DataLab