README.md

dictionary

AppVeyor build status Travis build status Coverage status

Overview

Dictionary implements dict, a user-friendly hashmap based on R environments.

Installation

You can install the development version from GitHub:

library(devtools)
install_github("skubicius/dictionary")

Examples

dict supports several constructors:

library(dictionary)
dict(hello = "world")
# A dict of size 1
# 'hello':  chr "world"

dict(list(seq = seq(10), double = pi))
# A dict of size 2
# 'double':  num 3.14
# 'seq':  int [1:10] 1 2 3 4 5 6 7 8 9 10

vectorized assignments:

d <- dict()
d[c("one", "two")] <- list("value", TRUE)
d
# A dict of size 2
# 'one':  chr "value"
# 'two':  logi TRUE

as well as vectorized subscripting with a default value:

d$get(c("two", "three"), default = "NOT FOUND")
# [[1]]
# [1] TRUE
# 
# [[2]]
# [1] "NOT FOUND"

It also implements items function for convenient iteration through its key/value pairs. Note that, like R environments, dict is not an ordered data structure:

d <- dict(letters, seq_along(letters))
d
# A dict of size 26
# 'f':  int 6
# 'g':  int 7
# 'h':  int 8
# 'i':  int 9
# 'j':  int 10
# ... with 21 more item(s)
for (item in items(d)) {
  if (item$value > 23)
    print(item$key)
}
# [1] "x"
# [1] "y"
# [1] "z"


skubicius/dictionary documentation built on May 7, 2019, 7:17 p.m.