Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/iqis/stash

Naive on-disk caching in R
https://github.com/iqis/stash

Last synced: 8 days ago
JSON representation

Naive on-disk caching in R

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# stash

[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/iqis/stash?branch=master&svg=true)](https://ci.appveyor.com/project/iqis/stash)
[![Travis build status](https://travis-ci.org/iqis/stash.svg?branch=master)](https://travis-ci.org/iqis/stash)
[![Codecov test coverage](https://codecov.io/gh/iqis/stash/branch/master/graph/badge.svg)](https://codecov.io/gh/iqis/stash?branch=master)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/stash)](https://cran.r-project.org/package=stash)

Creates a cache in binary in the file system for any R object, returning a reference to the cache file. This is useful if have many R objects to deal with, an cannot fit them all at once in your memory.

## Installation

```{r eval = FALSE}
devtools::install_github("iqis/stash")
```

## Example

```{r include = TRUE}
require(stash)
require(magrittr)
```

Make a stash.
```{r}
mtc_stash <- stash(mtcars)
mtc_stash
```

This means that mtcars is written into the above location. (It is also thus exposed that I use Windows.)

Access the stash's content with an empty `[]`.
```{r}
mtc_stash[] %>% head()
```

If you need to do any subsetting, you may chain `[]` or `$` right after.
```{r}
mtc_stash[][1:5, "mpg"]
mean(mtc_stash[]$cyl)
```

The object also provides access other useful information.
```{r}
mtc_stash$obj_class
mtc_stash$obj_size
mtc_stash$file_path
mtc_stash$has_stash_file()
mtc_stash$has_content()
```

Currently, as the data set is stashed on to the disc, we don't have a copy in the memory. But we can load it.
```{r}
mtc_stash$has_content()
mtc_stash$load_content()
mtc_stash$has_content()
mtc_stash[]
```

We can also remove the in-memory content to release memory. But we still can read from the disk as in the beginning.
```{r}
mtc_stash$remove_content()
mtc_stash$has_content()
```

```{r}
mtc_stash[]
```

Finally we can also remove the stash on the disk. If we do this now, we will end with no data anywhere.
```{r error = TRUE}
mtc_stash$remove_stash()
mtc_stash$has_stash_file()
mtc_stash[]
```