https://github.com/richfitz/thor
:zap::computer::zap: R client for the Lightning Memory-Mapped Database
https://github.com/richfitz/thor
Last synced: 24 days ago
JSON representation
:zap::computer::zap: R client for the Lightning Memory-Mapped Database
- Host: GitHub
- URL: https://github.com/richfitz/thor
- Owner: richfitz
- License: other
- Created: 2017-08-08T09:34:07.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-09-17T16:37:51.000Z (7 months ago)
- Last Synced: 2024-10-13T17:49:40.961Z (6 months ago)
- Language: C
- Homepage: https://richfitz.github.io/thor
- Size: 811 KB
- Stars: 52
- Watchers: 3
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - richfitz/thor - :zap::computer::zap: R client for the Lightning Memory-Mapped Database (C)
README
# thor
[](https://www.repostatus.org/)
[](https://github.com/richfitz/thor/actions)
[](https://app.codecov.io/github/richfitz/thor?branch=master)
[](https://cran.r-project.org/package=thor)```{r, echo = FALSE, results = "hide"}
knitr::opts_chunk$set(error = FALSE)
```An R interface to [LMDB](https://github.com/LMDB/lmdb). LMDB is an embedded transactional key-value store and this package provides R mappings to it. It wraps the entire LMDB interface, except for support for duplicated keys.
## Documentation
The package comes with a vignette that describes the main features of the package and of LMDB - see [here](https://richfitz.github.io/thor/articles/thor.html) for a version online. The package also has reference documentation for all methods. It may be useful to refer to the [LMDB documentation](http://lmdb.tech/doc) along side the reference documentation for some details (but hopefully not too much).
## Usage
Everything starts by creating an environment (which lives at a point in the file system), and then using methods of the environment object to interact with the database
```{r}
env <- thor::mdb_env(tempfile())
env
``````{r}
env$put("hello", "world")
env$exists("hello")
env$get("hello") # world
env$del("hello")
```LMDB is _transactional_, and `thor` exposes this like so:
```{r}
txn <- env$begin(write = TRUE)
txn
```Only one write transaction is active at a given point in time. There can be an unlimited number of read transactions.
```
txn$put("key", "value")
env$get("key", missing_is_error = FALSE) # NULL - not committed yet
txn$commit()
env$get("key") # new transactions see the value
```There is a cursor interface for advanced features (see the vignette). Both keys and values can be strings or binary value, the latter working well with `serialize`. For efficient use from R, `thor` extends the LMDB interface to implement bulk reads, writes and deletes (`mget`, `mput` and `mdel`).
## Performance
lmdb is an extremely fast database, but this package may be much less fast than the underlying library. In order to make the interface safe to use from R, there is quite a bit of error checking, and the length of time involved in calling methods in R6 objects is orders of magnitude slower than performing an action on an lmdb database (this is not R6's fault and primarily caused by the cost of S3 method lookup for `$` on an object with a class attribute). The vectorised functions will help here (e.g., `mget`, `mput`), so prefer these where practical if speed is a concern.
## Installation
Install from CRAN with
```r
install.packages("thor")
```If you want to try the development version from github, you can install with
```r
devtools::install_github("richfitz/thor", upgrade = FALSE)
```## License
MIT + file LICENSE © [Rich FitzJohn](https://github.com/richfitz). The package contains included code from lmdb which it itself under the "OpenLDAP Public License" - see [`inst/LICENSE.lmdb`](inst/LICENSE.lmdb) for details