storeCache: Stores as a cache an already-produced R object

Description Usage Arguments Details Examples

View source: R/storeCache.R

Description

Sometimes you use significant computational power to create an object, but you didn't cache it with simpleCache. Oops, maybe you wish you had, after the fact. This function lets you store an object in the environment so it could be loaded by future calls to simpleCache.

Usage

1
2
storeCache(cacheName, cacheDir = getOption("RCACHE.DIR"),
  cacheSubDir = NULL, recreate = FALSE)

Arguments

cacheName

Unique name for the cache (and R object to be cached).

cacheDir

The directory where caches are saved (and loaded from). Defaults to the global RCACHE.DIR variable

cacheSubDir

You can specify a subdirectory within the cacheDir variable. Defaults to NULL.

recreate

Forces reconstruction of the cache

Details

This can be used in interactive sessions, but could also be used for another use case: you have a complicated set of instructions (too much to pass as the instruction argument to simpleCache), so you could just stick a call to storeCache at the end.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# choose location to store caches
cacheDir = tempdir()
cacheDir
setCacheDir(cacheDir)

# build some caches
simpleCache("normSample", { rnorm(5e3, 0,1) }, recreate=TRUE, timer=TRUE)
simpleCache("normSample", { rnorm(5e3, 0,1) })
simpleCache("normSample", { rnorm(5e3, 0,1) }, reload=TRUE)

# storing a cache after-the-fact
normSample2 = rnorm(10, 0, 1)
storeCache("normSample2")

# what's available?
listCaches()

# load a cache
simpleCache("normSample")

# load multiples caches
loadCaches(c("normSample", "normSample2"), reload=TRUE)

databio/simpleCache documentation built on Nov. 26, 2018, 9:39 p.m.