Sugar function wrapping [Dictionary]$new.

dct(..., x = list(...), types = NULL)

Arguments

...

(ANY)
Named arguments with names corresponding to the items to add to the dictionary, where the keys are the names and the values are the elements. Names must be unique.

x

(list())
A named list with the names corresponding to the items to add to the dictionary, where the keys are the list names and the values are the list elements. Names must be unique.

types

(character())
If non-NULL then types creates a typed dictionary in which all elements of the dictionary must inherit from these types. Any class can be given to types as long as there is a valid as.character method associated with the class.

Examples

# untyped
dct(a = 1, b = 2, c = "a")
#> {a: 1, b: 2, c: a} 

# typed - class is forced
dct(a = 1L, b = 2L, c = 3L, types = "integer")
#> {a: 1, b: 2, c: 3} 

# list constructor
dct(x = list(a = 1, b = 2, c = "a"))
#> {a: 1, b: 2, c: a} 

# with R6
d <- dct(a = 1)
dct(d = d)
#> {d: {a: 1}}