datanode: Cache the result of a given expression.

Description Usage Arguments Details Value

View source: R/datanode.R

Description

Evaluates an expression and caches its result. If a cache exists, the expression is re-evaluated only if one of the dependency files is more recent than the cache.

Usage

1
2
3
datanode(path, expr, force = FALSE, depends_on = character(0), io = if
  (grepl("(?i).*\\.csv$", path)) csv_io else if (grepl("(?i).*\\.RData$",
  path)) rdata_io else rds_io, write_args = NULL, read_args = NULL, ...)

Arguments

path

the file caching the result of expr

expr

the expression to be evaluated if triggered

force

whether to force the evaluation of the expression expr and the update of its cache, defaults to TRUE

depends_on

a character vector of files on which the evaluation of the expression expr depends on.

io

a list with two named function read and write. read takes path and args as arguments, and write takes in addition data, path and args. args are a list of additional arguments possibly to the underlying reading or writing functions. Implementations for csv_io, rdata_io and rds_io are provided. The default value depends on the extension of the file described by the path parameter: .csv, .RData and .rds corresponding to the 3 io implementations, defaulting to rds_io.

write_args

a list of additional parameters to the io$write function.

read_args

a list of additional parameters to the io$read function.

...

additinal parameters to the io$read function, concatenated after the list in read_args.

Details

The given expression expr is evaluated only if one of the following condition is true:

- the file identified in path does *not* exist; or - force is TRUE; or - the latest modified time of the files in depends_on is later than the modified time of the file in path.

Value

the result of the evaluation of the expression expr if triggered, or its cached value stored in path otherwise


jullybobble/datanodes documentation built on May 20, 2019, 4:23 a.m.