cacheOperation | R Documentation |
Cache an operation to disk to save computation time in the future. A hash of the function and arguments is generated to avoid erroneous caching but any global variables or arguments excluded by EXCLUDE are not checked and are vulnerable erroneous output if they are changed.
cacheOperation( cacheFile, operation, ..., OVERWRITE = FALSE, VOCAL = TRUE, EXCLUDE = NULL )
cacheFile |
File location to save data to |
operation |
A function taking ... arguments and returning object to be stored |
... |
Arguments for operation function |
OVERWRITE |
If FALSE throw an error if hash of ... changes from cached values. If TRUE redo operation and overwrite cache without asking |
VOCAL |
If TRUE report on status of caching |
EXCLUDE |
Vector of names of arguments to exclude from md5 digest comparison (for very large arguments) |
Output from operation function with ... arguments
cache<-tempfile() cacheOperation(cache,mean,1:10) cacheOperation(cache,mean,1:10) cacheOperation(cache,mean,x=1:20,OVERWRITE=TRUE) cacheOperation(cache,mean,x=1:20,OVERWRITE=TRUE,EXCLUDE='x') #Note that EXCLUDEd arguments are not checked and can generate false output y<-2 cacheOperation(cache,function(x)sum(x^y),1:10,OVERWRITE=TRUE) #Note that global variables can generate false output y<-3 cacheOperation(cache,function(x)sum(x^y),1:10,OVERWRITE=TRUE) cacheOperation(cache,mean,x=1:100,OVERWRITE=TRUE,EXCLUDE='x')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.