Skip to contents

Hash table

Usage

hash_table(keys, values)

hash_table_empty(cl)

Arguments

keys

Keys as a character vector.

values

Values. It supports vectors in the following classes: integer, logical, numeric, character, Date, POSIXct and list (i.e. a list of R objects).

cl

One of "integer", "logical", "numeric", "character", "Date", "POSIXct" and "Robj".

Value

A hash_table object.

Examples

hash_table(c("a", "b"), 1:2L)
#> A hash table with 2 key-value (integer) pairs
#>   b => 2
#>   a => 1
hash_table(c("a", "b"), c(TRUE, FALSE))
#> A hash table with 2 key-value (logical) pairs
#>   b => FALSE
#>   a => TRUE
hash_table(c("a", "b"), c(0.1, 0.2))
#> A hash table with 2 key-value (numeric) pairs
#>   b => 0.2
#>   a => 0.1
hash_table(c("a", "b"), c("one", "two"))
#> A hash table with 2 key-value (character) pairs
#>   b => two
#>   a => one
hash_table(c("a", "b"), as.Date(c("2025-01-01", "2025-02-01")))
#> A hash table with 2 key-value (Date) pairs
#>   b => 2025-02-01
#>   a => 2025-01-01
hash_table(c("a", "b"), as.POSIXct(c("2025-01-01 00:00:01", "2025-02-01 00:00:01")))
#> A hash table with 2 key-value (POSIXct) pairs
#>   b => 2025-02-01 00:00:01
#>   a => 2025-01-01 00:00:01
hash_table(c("a", "b"), list(1:10, letters))
#> A hash table with 2 key-value (R object) pairs
#>   b => character [1:26] a b c d e f g h i j k l m n o p q r s t u v w x y z
#>   a => integer [1:10] 1 2 3 4 5 6 7 8 9 10

# a nested hash table
h = hash_table_empty("Robj")
h$a = hash_table_empty("Robj")
h$a$b = hash_table("c", 1L)
h$a$b$c
#> [1] 1
hash_table_empty("integer")
#> A hash table with 0 key-value (integer) pair
hash_table_empty("character")
#> A hash table with 0 key-value (character) pair
hash_table_empty("Robj")
#> A hash table with 0 key-value (R object) pair