memo: Memoize a function.

View source: R/cache.R

memoR Documentation

Memoize a function.

Description

Memoize a function.

Usage

memo(fn, cache = lru_cache(5000), key = hybrid_key, ...)

Arguments

fn

A function to wrap. It should be a pure function (i.e. it should not cause side effects, and should not depend on any variables that may change.) It should not be a nonstandard-evaluating function. All arguments will be forced by the wrapper.

cache

A cache to use. Defaults to a new instance of lru_cache. Caches may be shared between memoized functions.

key

A hashing strategy. The default "hybrid_key" first checks for pointer equivalence and then falls back to using a hash of the arguments. 'pointer_key' uses just pointer equivalence, and 'digest_key' always performs a hash.

...

Further arguments passed on to key.


memo documentation built on May 29, 2024, 4:18 a.m.