knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
r2r
provides a flexible implementation of hash tables in R, allowing for:
You can install the released version of r2r
from CRAN with:
install.packages("r2r")
and the development version from my R-universe repository, with:
install.packages("r2r", repos = "https://vgherard.r-universe.dev")
library(r2r) m <- hashmap() # Insert and query a single key-value pair m[[ "user" ]] <- "vgherard" m[[ "user" ]] # Insert and query multiple key-value pairs m[ c(1, 2, 3) ] <- c("one", "two", "three") m[ c(1, 3) ] # Keys and values can be arbitrary R objects m[[ lm(mpg ~ wt, mtcars) ]] <- c(TRUE, FALSE, TRUE) m[[ lm(mpg ~ wt, mtcars) ]]
For further details, including an introductory vignette illustrating the features of r2r
hash maps, you can consult the r2r
website. If you encounter a bug, want to suggest a feature or need further help, you can open a GitHub issue.
hash
CRAN package {hash}
also offers an implementation of hash tables based on R environments. The two tables below offer a comparison between {r2r}
and {hash}
(for more details, see the benchmarks Vignette)
knitr::kable( data.frame( Feature = c( "Basic data structure", "Arbitrary type keys", "Arbitrary type values", "Arbitrary hash function", "Arbitrary key comparison function", "Throw or return default on missing keys", "Hash table inversion" ), r2r = c("R environment", "X", "X", "X", "X", "X", ""), hash = c("R environment", "", "X", "", "", "", "X") ), align = "c", caption = "Features supported by {r2r} and {hash}." )
knitr::kable( data.frame( Task = c( "Key insertion", "Key query", "Key deletion" ), Comparison = c( "{r2r} ~ {hash}", "{r2r} < {hash}", "{r2r} << {hash}" ) ), align = "c", caption = "Performances of {r2r} and {hash} for basic hash table operations." )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.