{r2r} now on CRAN

Data Structures R

Introducing {r2r}, an R implementation of hash tables.

Valerio Gherardi https://vgherard.github.io
07-06-2021

Introduction

My package {r2r} (v0.1.1) has been accepted by CRAN, and is now available for download from the public repository.

r2r

CRAN status R-CMD-check Codecov test coverage

r2r provides a flexible implementation of hash tables in R, allowing for:

Installation

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")

Usage

library(r2r)
m <- hashmap()

# Insert and query a single key-value pair
m[[ "user" ]] <- "vgherard"
m[[ "user" ]]
[1] "vgherard"
# Insert and query multiple key-value pairs
m[ c(1, 2, 3) ] <- c("one", "two", "three")
m[ c(1, 3) ]
[[1]]
[1] "one"

[[2]]
[1] "three"
# Keys and values can be arbitrary R objects
m[[ lm(mpg ~ wt, mtcars) ]] <- c(TRUE, FALSE, TRUE)
m[[ lm(mpg ~ wt, mtcars) ]]
[1]  TRUE FALSE  TRUE

Getting help

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.

Comparison with 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)

Table 1: Features supported by {r2r} and {hash}.
Feature r2r hash
Basic data structure R environment R environment
Arbitrary type keys X
Arbitrary type values X X
Arbitrary hash function X
Arbitrary key comparison function X
Throw or return default on missing keys X
Hash table inversion X
Table 2: Performances of {r2r} and {hash} for basic hash table operations.
Task Comparison
Key insertion {r2r} ~ {hash}
Key query {r2r} < {hash}
Key deletion {r2r} << {hash}

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY-SA 4.0. Source code is available at https://github.com/vgherard/vgherard.github.io/, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".

Citation

For attribution, please cite this work as

Gherardi (2021, July 6). vgherard: {r2r} now on CRAN. Retrieved from https://vgherard.github.io/posts/2021-07-06-r2r/

BibTeX citation

@misc{gherardi2021{r2r},
  author = {Gherardi, Valerio},
  title = {vgherard: {r2r} now on CRAN},
  url = {https://vgherard.github.io/posts/2021-07-06-r2r/},
  year = {2021}
}