-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
98 lines (74 loc) · 2.43 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
---
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%"
)
```
# stash
<!-- badges: start -->
[![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)
<!-- badges: end -->
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[]
```