Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions coding-practices/benchmarking.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ n_iterations <- 1000

- [`{bench}`](https://bench.r-lib.org/) - Accurate benchmarking
- [`{profvis}`](https://profvis.r-lib.org/) - Interactive profiling
- [`{memoise}`](https://memoise.r-lib.org/) - Function-call caching to eliminate repeated bottlenecks (@sec-memoise)
- [Measuring Performance](https://adv-r.hadley.nz/perf-measure.html) chapter in Advanced R
- [Improving Performance](https://adv-r.hadley.nz/perf-improve.html) chapter in Advanced R
- [`{touchstone}`](https://github.com/lorenzwalthert/touchstone) - CI benchmarking with PR comments
18 changes: 16 additions & 2 deletions coding-practices/r-lib-packages.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,22 @@ This manual requires `{here}` for file paths (see @sec-here-package-practices).
### [`{memoise}`](https://memoise.r-lib.org/) {#sec-memoise}

[`{memoise}`](https://memoise.r-lib.org/) adds memoisation (function-call caching) to R functions.
Wrapping a function with `memoise()` causes it to cache results so repeated calls
with the same arguments return the cached value instead of recomputing.
Wrapping an expensive, pure function with `memoise::memoise()` causes it to cache computed return values
in memory or on disk,
so repeated calls with identical arguments return instantly from cache instead of recomputing.
It supports multiple storage backends via the `cache` argument
(such as `cachem::cache_mem()` for in-memory caching
and `cachem::cache_disk()` for persistent disk caching across sessions),
and provides `memoise::forget()` to clear caches,
`memoise::is.memoised()` to test whether a function is memoised,
and `memoise::has_cache()` to check whether specific arguments have cached results.
Use `{memoise}` only for deterministic functions without side effects
(such as pure mathematical evaluations,
stable API queries,
or idempotent data processing pipelines).
Do not memoise stochastic simulation routines or functions that draw pseudorandom numbers;
memoisation suppresses stochastic variation across calls with identical arguments,
returning identical pseudorandom draws unless an explicit RNG seed argument is passed and sets the generator state deterministically.
Comment thread
d-morrison marked this conversation as resolved.
Outdated

### [`{scales}`](https://scales.r-lib.org/) {#sec-scales}

Expand Down
Loading