Learn R Programming

lares (version 4.10.6)

cache_write: Cache Save and Load (Write and Read)

Description

This function lets the user save and load a cache of any R object to improve timings and UX.

Usage

cache_write(
  data,
  base = "temp",
  cache_dir = getOption("LARES_CACHE_DIR"),
  ask = FALSE,
  quiet = FALSE
)

cache_read( base, cache_dir = getOption("LARES_CACHE_DIR"), ask = FALSE, quiet = FALSE )

cache_exists( base = NULL, cache_dir = getOption("LARES_CACHE_DIR"), filename = NULL )

cache_clear(cache_dir = getOption("LARES_CACHE_DIR"))

Arguments

data

Object

base

Character vector. Unique name for your cache file. You can pass a character vector with multiple elements that will be concatenated.

cache_dir

Character. Where do you want to save you cache files? By default they'll be stored on tempdir() but you can change it using this parameter or setting a global option called "LARES_CACHE_DIR".

ask

Boolean. If cache exists, when reading: (interactive) ask the user if the cache should be used to proceed or ignored; when writing, (interactive) ask the user if the cache should be overwritten.

quiet

Boolean. Keep quiet? If not, message will be shown.

filename

Character. File name to check existence.

Value

cache_write. No return value, called for side effects.

cache_read. R object. Data from cache file or NULL if no cache found.

cache_exists. Boolean. Result of base existence.

cache_clear. Invisible vector containing cache file names removed.

Examples

Run this code
# NOT RUN {
x = list(a = 1, b = 2:4)
base <- c(as.character(Sys.Date()), "A","B","C")
cache_write(x, base)
cache_read(base, ask = FALSE)
# }

Run the code above in your browser using DataLab