Coming from Python, the absence of a real dictionary in R has annoyed me for quite some time. Now, I actually needed to use vectors as keys in R:
library(dict) d <- dict() d[] <- 42 d[[c(2, 3)]] <- "Hello!" d[["foo"]] <- "bar" d[] d[[c(2, 3)]] d$get("not here", "default") d$keys() d$values() d$items() # [[ ]] gives an error for unknown keys d[["?"]]
Under the hood, separate C++ dictionaries (unordered_map) are created for the different types of keys. Using R's flexible types that are reflected in Rcpp (as SEXP), such a dictionary can store both numbers and strings (and other objects) at the same time.
The package is available on GitHub: https://github.com/mkuhn/dict