README.md

Stash

I work with lots of data. Oftentimes I need to tell my program, “Hey, this is a heavy function. Save the result, OK?” This is the role of caching libraries. There are many available on CRAN for R code, but none fit the philosophy I had when working on my thesis.

Philosophy

The philosphy of stash is that the user of this library, like me, is rushed and forgetful. This leads to several design considerations:

Interface

The most important function do.call.stash, which mimics the syntax of base R’s do.call.

library(stash)

# Default cache location is ~/.stash-r/cache/"
# For a demo, put it in a temporary directory.
cache_dir <- file.path(tempdir(), "readme-test")
dir.create(cache_dir)
options(stash.cache_path = cache_dir)

heavy_function <- function(x) {
  Sys.sleep(3)
  mean(x)
}

result <- NULL
system.time({result <- do.call.stash(heavy_function, list(c(1:20)))})
##    user  system elapsed 
##   0.003   0.000   3.005
result
## [1] 10.5
system.time({result <- do.call.stash(heavy_function, list(c(1:20)))})
##    user  system elapsed 
##   0.001   0.000   0.001
result
## [1] 10.5

The other is setting the directory to store cached results, through options(stash.cache_path = "the/path/to/your/cache/"). This call is visible above.

Contact

For comments, questions, and requests related to this library, Github issues are best.



MrMallIronmaker/stash documentation built on Feb. 5, 2022, 8:12 a.m.