Last active
August 14, 2025 15:39
-
-
Save allanjust/045660f32409f0507c97917b7d0c681d to your computer and use it in GitHub Desktop.
Demonstration of basic use of pairmemo in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## playing with pairmemo for cacheing in R | |
| ## https://arfer.net/code/pairmemo | |
| # remotes::install_github("Kodiologist/pairmemo") | |
| ## this demo uses tempdir but you would ordinarily use a persistent cache... | |
| temp <- tempdir() | |
| pairmemo::define( | |
| my.cool.function <- function(foo, bar) | |
| {message("Calling my cool function") | |
| Sys.sleep(1) | |
| foo + bar}, | |
| directory = temp) | |
| my.cool.function(1, 2) | |
| my.cool.function(1, 2) # Cached, so no message is printed. | |
| pairmemo::clear(my.cool.function) # Clear the cache. | |
| my.cool.function(1, 2) | |
| # take a look in the cache | |
| list.files(file.path(temp, "my.cool.function")) | |
| pairmemo::metadata(my.cool.function) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment