Skip to content

Instantly share code, notes, and snippets.

@cdiener cdiener/cache.R
Last active Aug 29, 2015

Embed
What would you like to do?
cache operator for R
# Caching operator executes command if there is no saved version of the data
# just delete the saved file and code will be run again
'%c%' = function(ex, file) if(file.exists(file), env=parent.frame(4)) load(file) else evalq(ex))
# Example
# first execution
{ x <- rnorm(1e6); save(x, file="cache.Rd") } %c% "cache.Rd" # executes the sampling
# second execution ("cache.Rd" exists now)
{ x <- rnorm(1e6); save(x, file="cache.Rd") } %c% "cache.Rd" # does not execute but reads from cache.Rd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.