Evaluate an expression and cache its result in the package storage
environment (session$storage) under a given name. The expression is only
re-evaluated when the cached value is missing, when overwrite = TRUE, or
when the global option fundsr.reload is TRUE. Optionally merges additional
fund/index mappings into session$state$fund_index_map.
Usage
store_timeseries(
var_name,
expr,
fund_index_map = NULL,
overwrite = FALSE,
postprocess = identity,
session = NULL
)Arguments
- var_name
Character scalar. Name of the variable to store in
session$storage.- expr
An expression. Evaluated in the caller's environment when (re)computing the cached value.
- fund_index_map
Optional named vector of fund/index pairs to merge into
session$state$fund_index_map. Names are used as keys, values should be indices.- overwrite
Logical scalar. If
TRUE, recompute and replace any existing cached value, regardless offundsr.reload.- postprocess
Function applied to the computed value before caching. Only used when the value is (re)computed (i.e. not applied when a cached value is reused). Defaults to
base::identity().- session
Optional
fundsr_sessionobject. Defaults to the package default session whenNULL.
Details
expr is evaluated in the environment where store_timeseries() is called
(i.e. the caller's environment), then assigned into session$storage under
var_name.
Caching behavior is controlled by:
overwrite = TRUE(always recompute),options(fundsr.reload = TRUE)(force recomputation globally), orabsence of
var_nameinsession$storage(compute once).
If fund_index_map is supplied, it is merged into session$state$fund_index_map
via name-based assignment: existing entries with the same names are replaced.
See also
Other fund/index workflow functions:
add_data_loader(),
build_all_series(),
clear_data_loaders(),
clear_storage(),
get_storage(),
join_env(),
load_fund(),
run_data_loaders()
