-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
111 lines (89 loc) · 3.51 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# r2r
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/r2r)](https://CRAN.R-project.org/package=r2r)
[![R-CMD-check](https://github.com/vgherard/r2r/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/vgherard/r2r/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/vgherard/r2r/graph/badge.svg)](https://app.codecov.io/gh/vgherard/r2r)
[![R-universe status](https://vgherard.r-universe.dev/badges/r2r)](https://vgherard.r-universe.dev/)
[![Website](https://img.shields.io/badge/Website-here-blue)](https://vgherard.github.io/r2r/)
[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text={r2r}:%20R-Object%20to%20R-Object%20Hash%20Maps&url=https://vgherard.github.io/r2r&via=ValerioGherardi&hashtags=rstats,datastructures,hashtables)
<!-- badges: end -->
[`r2r`](https://vgherard.github.io/r2r/) provides a flexible implementation of hash tables in R, allowing for:
- arbitrary R objects as keys and values,
- arbitrary key comparison and hash functions,
- customizable behaviour (throw or return a default value) on missing key exceptions.
## Installation
You can install the released version of `r2r` from [CRAN](https://CRAN.R-project.org/package=r2r) with:
``` r
install.packages("r2r")
```
and the development version from [my R-universe repository](https://vgherard.r-universe.dev/), with:
``` r
install.packages("r2r", repos = "https://vgherard.r-universe.dev")
```
## Usage
```{r}
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) ]]
```
## Getting help
For further details, including an introductory vignette illustrating the features of `r2r` hash maps, you can consult the `r2r` [website](https://vgherard.github.io/r2r/). If you encounter a bug, want to suggest a feature or need further help, you can [open a GitHub issue](https://github.com/vgherard/r2r/issues).
## Comparison with `hash`
CRAN package [`{hash}`](https://CRAN.R-project.org/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](https://vgherard.github.io/r2r/articles/benchmarks.html) Vignette)
```{r echo=FALSE}
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}."
)
```
```{r echo=FALSE}
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."
)
```