Skip to content

Instantly share code, notes, and snippets.

@allanjust
Last active August 14, 2025 15:39
Show Gist options
  • Select an option

  • Save allanjust/045660f32409f0507c97917b7d0c681d to your computer and use it in GitHub Desktop.

Select an option

Save allanjust/045660f32409f0507c97917b7d0c681d to your computer and use it in GitHub Desktop.
Demonstration of basic use of pairmemo in R
## 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