MyNixOS website logo
Description

Simply Caching R Objects.

Provides intuitive functions for caching R objects, encouraging reproducible, restartable, and distributed R analysis. The user selects a location to store caches, and then provides nothing more than a cache name and instructions (R code) for how to produce the R object. Also provides some advanced options like environment assignments, recreating or reloading caches, and cluster compute bindings (using the 'batchtools' package) making it flexible enough for use in large-scale data analysis projects.

simpleCache: R caching for restartable analysis

Travis CI status

simpleCache is an R package providing functions for caching R objects. Its purpose is to encourage writing reusable, restartable, and reproducible analysis pipelines for projects with massive data and computational requirements.

Like its name indicates, simpleCache is intended to be simple. You choose a location to store your caches, and then provide the function with nothing more than a cache name and instructions (R code) for how to produce the R object. While simple, simpleCache also provides some advanced options like environment assignments, recreating caches, reloading caches, and even cluster compute bindings (using the batchtools package) making it flexible enough for use in large-scale data analysis projects.


Installing simpleCache

simpleCache is on CRAN and can be installed as usual:

install.packages("simpleCache")

Running simpleCache

simpleCache comes with a single primary function (simpleCache()) that will do almost everything you need. In short, you run it with a few lines like this:

library(simpleCache) 
setCacheDir(tempdir())
simpleCache("normSample", { rnorm(1e7, 0,1) }, recreate=TRUE)
simpleCache("normSample", { rnorm(1e7, 0,1) })

simpleCache also interfaces with the batchtools package to let you build caches on any cluster resource manager.


Highlights of exported functions

  • simpleCache(): Creates and caches or reloads cached results of provided R instruction code
  • listCaches(): Lists all of the caches available in the cacheDir
  • deleteCaches(): Deletes cache(s) from the cacheDir
  • setCacheDir(): Sets a global option for a cache directory so you don't have to specify one in each simpleCache call
  • simpleCacheOptions(): Views all of the simpleCache global options that have been set

simpleCache Philosophy

The use case I had in mind for simpleCache is that you find yourself constantly recalculating the same R object in several different scripts, or repeatedly in the same script, every time you open it and want to continue that project. SimpleCache is well-suited for interactive analysis, allowing you to pick up right where you left off in a new R session, without having to recalculate everything. It is equally useful in automatic pipelines, where separate scripts may benefit from loading, instead of recalculating, the same R objects produced by other scripts.

R provides some base functions (save, serialize, and load) to let you save and reload such objects, but these low-level functions are a bit cumbersome. simpleCache simply provides a convenient, user-friendly interface to these functions, streamlining the process. For example, a single simpleCache call will check for a cache and load it if it exists, or create it if it does not. With the base R save and load functions, you can't just write a single function call and then run the same thing every time you start the script -- even this simple use case requires additional logic to check for an existing cache. simpleCache just does all this for you.

The thing to keep in mind with simpleCache is that the cache name is paramount. simpleCache assumes that your name for an object is a perfect identifier for that object; in other words, don't cache things that you plan to change.

Contributing

simpleCache is licensed under the 2-Clause BSD License. Questions, feature requests and bug reports are welcome via the issue queue. The maintainer will review pull requests and incorporate contributions at his discretion.

For more information refer to the contributing document and pull request / issue templates in the .github folder of this repository.

Metadata

Version

0.4.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows