As part of a reproducible workflow, caching of function calls, code chunks, and other elements of a project is a critical component. The objective of a reproducible workflow is is likely that an entire work flow from raw data to publication, decision support, report writing, presentation building etc., could be built and be reproducible anywhere, on any computer, operating system, with any starting conditions, on demand. The reproducible::Cache
function is built to work with any R function.
Cache
uses 2 key the archivist
functions saveToLocalRepo
and loadFromLocalRepo
, but does not use archivist::cache
. Similar to archivist::cache
, there is some reliance on digest::digest
to determine whether the arguments are identical in subsequent iterations. It also but does many things that make standard caching with digest::digest
don’t work reliably between systems. For these, the function .robustDigest
is introduced to make caching transferable between systems. This is relevant for file paths, environments, parallel clusters, functions (which are contained within an environment), and many others (e.g., see ?.robustDigest
for methods). Cache
also adds important elements like automated tagging and the option to retrieve disk-cached values via stashed objects in memory using memoise::memoise
. This means that running Cache
1, 2, and 3 times on the same function will get progressively faster. This can be extremely useful for web apps built with, say shiny
.
Any function can be cached using: Cache(FUN = functionName, ...)
.
This will be a slight change to a function call, such as: projectRaster(raster, crs = crs(newRaster))
to Cache(projectRaster, raster, crs = crs(newRaster))
.
This is particularly useful for expensive operations.
## Loading required package: sp
library(reproducible)
tmpDir <- file.path(tempdir(), "reproducible_examples", "Cache")
checkPath(tmpDir, create = TRUE)
## [1] "C:/Users/emcintir.L-VIC-A023744/AppData/Local/Temp/RtmpwvOhxA/reproducible_examples/Cache"
ras <- raster(extent(0, 1000, 0, 1000), vals = 1:1e6, res = 1)
crs(ras) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +ellps=WGS84"
newCRS <- "+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
# No Cache
system.time(map1 <- projectRaster(ras, crs = newCRS))
## user system elapsed
## 1.93 0.14 2.08
# With Cache -- a little slower the first time because saving to disk
system.time(map1 <- Cache(projectRaster, ras, crs = newCRS, cacheRepo = tmpDir,
notOlderThan = Sys.time()))
## user system elapsed
## 2.26 0.28 2.57
# vastly faster the second time
system.time(map2 <- Cache(projectRaster, ras, crs = newCRS, cacheRepo = tmpDir))
## ...(Object to retrieve is large: 6.5 Mb)
## loading cached result from previous projectRaster call, adding to memoised copy
## user system elapsed
## 0.08 0.03 0.13
# even faster the third time
system.time(map3 <- Cache(projectRaster, ras, crs = newCRS, cacheRepo = tmpDir))
## ...(Object to retrieve is large: 6.5 Mb)
## loading memoised result from previous projectRaster call.
## user system elapsed
## 0.01 0.06 0.08
## [1] TRUE
## [1] TRUE
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:raster':
##
## extract
try(clearCache(tmpDir, ask = FALSE), silent = TRUE) # just to make sure it is clear
ranNumsA <- Cache(rnorm, 10, 16, cacheRepo = tmpDir)
# All same
ranNumsB <- Cache(rnorm, 10, 16, cacheRepo = tmpDir) # recovers cached copy
## loading cached result from previous rnorm call, adding to memoised copy
## loading memoised result from previous 'rnorm' pipe sequence call.
## loading memoised result from previous rnorm call.
ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a")
ranNumsB <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:b")
# access it again, from Cache
ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a")
## loading cached result from previous rnorm call, adding to memoised copy
## Cache size:
## Total (including Rasters): 504 bytes
## Selected objects (not including Rasters): 504 bytes
# keep only items accessed "recently" (i.e., only objectName:a)
onlyRecentlyAccessed <- showCache(tmpDir, userTags = max(wholeCache[tagKey == "accessed"]$tagValue))
## Cache size:
## Total (including Rasters): 504 bytes
## Selected objects (not including Rasters): 504 bytes
# inverse join with 2 data.tables ... using: a[!b]
# i.e., return all of wholeCache that was not recently accessed
toRemove <- unique(wholeCache[!onlyRecentlyAccessed], by = "artifact")$artifact
clearCache(tmpDir, toRemove, ask = FALSE) # remove ones not recently accessed
## Cache size:
## Total (including Rasters): 504 bytes
## Selected objects (not including Rasters): 504 bytes
## Cache size:
## Total (including Rasters): 0 bytes
## Selected objects (not including Rasters): 0 bytes
## Empty data.table (0 rows and 3 cols): md5hash,name,createdDate
ranNumsA <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:a")
ranNumsB <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:b")
# keep only those cached items from the last 24 hours
oneDay <- 60 * 60 * 24
keepCache(tmpDir, after = Sys.time() - oneDay, ask = FALSE)
## Cache size:
## Total (including Rasters): 504 bytes
## Selected objects (not including Rasters): 504 bytes
## artifact tagKey
## 1: 0b0c4f2cad84630f12497c0d05c107a9 format
## 2: 0b0c4f2cad84630f12497c0d05c107a9 name
## 3: 0b0c4f2cad84630f12497c0d05c107a9 class
## 4: 0b0c4f2cad84630f12497c0d05c107a9 date
## 5: 0b0c4f2cad84630f12497c0d05c107a9 cacheId
## 6: 0b0c4f2cad84630f12497c0d05c107a9 objectName
## 7: 0b0c4f2cad84630f12497c0d05c107a9 function
## 8: 0b0c4f2cad84630f12497c0d05c107a9 object.size
## 9: 0b0c4f2cad84630f12497c0d05c107a9 accessed
## 10: 0b0c4f2cad84630f12497c0d05c107a9 otherFunctions
## 11: 0b0c4f2cad84630f12497c0d05c107a9 otherFunctions
## 12: 0b0c4f2cad84630f12497c0d05c107a9 otherFunctions
## 13: 0b0c4f2cad84630f12497c0d05c107a9 otherFunctions
## 14: 0b0c4f2cad84630f12497c0d05c107a9 otherFunctions
## 15: 0b0c4f2cad84630f12497c0d05c107a9 otherFunctions
## 16: 0b0c4f2cad84630f12497c0d05c107a9 otherFunctions
## 17: 0b0c4f2cad84630f12497c0d05c107a9 otherFunctions
## 18: 0b0c4f2cad84630f12497c0d05c107a9 otherFunctions
## 19: 0b0c4f2cad84630f12497c0d05c107a9 otherFunctions
## 20: 0b0c4f2cad84630f12497c0d05c107a9 preDigest
## 21: 0b0c4f2cad84630f12497c0d05c107a9 preDigest
## 22: 623adedd3ce9c482c1ba68613776e7ba format
## 23: 623adedd3ce9c482c1ba68613776e7ba name
## 24: 623adedd3ce9c482c1ba68613776e7ba class
## 25: 623adedd3ce9c482c1ba68613776e7ba date
## 26: 623adedd3ce9c482c1ba68613776e7ba cacheId
## 27: 623adedd3ce9c482c1ba68613776e7ba objectName
## 28: 623adedd3ce9c482c1ba68613776e7ba function
## 29: 623adedd3ce9c482c1ba68613776e7ba object.size
## 30: 623adedd3ce9c482c1ba68613776e7ba accessed
## 31: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 32: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 33: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 34: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 35: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 36: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 37: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 38: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 39: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 40: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 41: 623adedd3ce9c482c1ba68613776e7ba preDigest
## 42: 623adedd3ce9c482c1ba68613776e7ba preDigest
## artifact tagKey
## tagValue createdDate
## 1: rda 2019-11-18 06:58:22
## 2: 0b0c4f2cad84630f12497c0d05c107a9 2019-11-18 06:58:22
## 3: numeric 2019-11-18 06:58:22
## 4: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 5: 3aef38d1fc02aee5 2019-11-18 06:58:22
## 6: b 2019-11-18 06:58:22
## 7: runif 2019-11-18 06:58:22
## 8: 1008 2019-11-18 06:58:22
## 9: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 10: vweave_rmarkdown 2019-11-18 06:58:22
## 11: process_file 2019-11-18 06:58:22
## 12: process_group 2019-11-18 06:58:22
## 13: process_group.block 2019-11-18 06:58:22
## 14: call_block 2019-11-18 06:58:22
## 15: block_exec 2019-11-18 06:58:22
## 16: in_dir 2019-11-18 06:58:22
## 17: timing_fn 2019-11-18 06:58:22
## 18: handle 2019-11-18 06:58:22
## 19: withVisible 2019-11-18 06:58:22
## 20: n:7eef4eae85fd9229 2019-11-18 06:58:22
## 21: .FUN:881ec847b7161f3c 2019-11-18 06:58:22
## 22: rda 2019-11-18 06:58:22
## 23: 623adedd3ce9c482c1ba68613776e7ba 2019-11-18 06:58:22
## 24: numeric 2019-11-18 06:58:22
## 25: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 26: f7bee22047b8d0c1 2019-11-18 06:58:22
## 27: a 2019-11-18 06:58:22
## 28: rnorm 2019-11-18 06:58:22
## 29: 1008 2019-11-18 06:58:22
## 30: 2019-11-18 06:58:21 2019-11-18 06:58:22
## 31: vweave_rmarkdown 2019-11-18 06:58:22
## 32: process_file 2019-11-18 06:58:22
## 33: process_group 2019-11-18 06:58:22
## 34: process_group.block 2019-11-18 06:58:22
## 35: call_block 2019-11-18 06:58:22
## 36: block_exec 2019-11-18 06:58:22
## 37: in_dir 2019-11-18 06:58:22
## 38: timing_fn 2019-11-18 06:58:22
## 39: handle 2019-11-18 06:58:22
## 40: withVisible 2019-11-18 06:58:22
## 41: n:7eef4eae85fd9229 2019-11-18 06:58:22
## 42: .FUN:4f604aa46882b368 2019-11-18 06:58:22
## tagValue createdDate
# Keep all Cache items created with an rnorm() call
keepCache(tmpDir, userTags = "rnorm", ask = FALSE)
## Cache size:
## Total (including Rasters): 504 bytes
## Selected objects (not including Rasters): 252 bytes
## artifact tagKey
## 1: 623adedd3ce9c482c1ba68613776e7ba format
## 2: 623adedd3ce9c482c1ba68613776e7ba name
## 3: 623adedd3ce9c482c1ba68613776e7ba class
## 4: 623adedd3ce9c482c1ba68613776e7ba date
## 5: 623adedd3ce9c482c1ba68613776e7ba cacheId
## 6: 623adedd3ce9c482c1ba68613776e7ba objectName
## 7: 623adedd3ce9c482c1ba68613776e7ba function
## 8: 623adedd3ce9c482c1ba68613776e7ba object.size
## 9: 623adedd3ce9c482c1ba68613776e7ba accessed
## 10: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 11: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 12: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 13: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 14: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 15: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 16: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 17: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 18: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 19: 623adedd3ce9c482c1ba68613776e7ba otherFunctions
## 20: 623adedd3ce9c482c1ba68613776e7ba preDigest
## 21: 623adedd3ce9c482c1ba68613776e7ba preDigest
## artifact tagKey
## tagValue createdDate
## 1: rda 2019-11-18 06:58:22
## 2: 623adedd3ce9c482c1ba68613776e7ba 2019-11-18 06:58:22
## 3: numeric 2019-11-18 06:58:22
## 4: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 5: f7bee22047b8d0c1 2019-11-18 06:58:22
## 6: a 2019-11-18 06:58:22
## 7: rnorm 2019-11-18 06:58:22
## 8: 1008 2019-11-18 06:58:22
## 9: 2019-11-18 06:58:21 2019-11-18 06:58:22
## 10: vweave_rmarkdown 2019-11-18 06:58:22
## 11: process_file 2019-11-18 06:58:22
## 12: process_group 2019-11-18 06:58:22
## 13: process_group.block 2019-11-18 06:58:22
## 14: call_block 2019-11-18 06:58:22
## 15: block_exec 2019-11-18 06:58:22
## 16: in_dir 2019-11-18 06:58:22
## 17: timing_fn 2019-11-18 06:58:22
## 18: handle 2019-11-18 06:58:22
## 19: withVisible 2019-11-18 06:58:22
## 20: n:7eef4eae85fd9229 2019-11-18 06:58:22
## 21: .FUN:4f604aa46882b368 2019-11-18 06:58:22
## tagValue createdDate
# Remove all Cache items that happened within a rnorm() call
clearCache(tmpDir, userTags = "rnorm", ask = FALSE)
## Cache size:
## Total (including Rasters): 252 bytes
## Selected objects (not including Rasters): 252 bytes
## Cache size:
## Total (including Rasters): 0 bytes
## Selected objects (not including Rasters): 0 bytes
## Empty data.table (0 rows and 3 cols): md5hash,name,createdDate
# default userTags is "and" matching; for "or" matching use |
ranNumsA <- Cache(runif, 4, cacheRepo = tmpDir, userTags = "objectName:a")
ranNumsB <- Cache(rnorm, 4, cacheRepo = tmpDir, userTags = "objectName:b")
# show all objects (runif and rnorm in this case)
showCache(tmpDir)
## Cache size:
## Total (including Rasters): 504 bytes
## Selected objects (not including Rasters): 504 bytes
## artifact tagKey
## 1: 106559c99d270496c331b4e50a597135 format
## 2: 106559c99d270496c331b4e50a597135 name
## 3: 106559c99d270496c331b4e50a597135 class
## 4: 106559c99d270496c331b4e50a597135 date
## 5: 106559c99d270496c331b4e50a597135 cacheId
## 6: 106559c99d270496c331b4e50a597135 objectName
## 7: 106559c99d270496c331b4e50a597135 function
## 8: 106559c99d270496c331b4e50a597135 object.size
## 9: 106559c99d270496c331b4e50a597135 accessed
## 10: 106559c99d270496c331b4e50a597135 otherFunctions
## 11: 106559c99d270496c331b4e50a597135 otherFunctions
## 12: 106559c99d270496c331b4e50a597135 otherFunctions
## 13: 106559c99d270496c331b4e50a597135 otherFunctions
## 14: 106559c99d270496c331b4e50a597135 otherFunctions
## 15: 106559c99d270496c331b4e50a597135 otherFunctions
## 16: 106559c99d270496c331b4e50a597135 otherFunctions
## 17: 106559c99d270496c331b4e50a597135 otherFunctions
## 18: 106559c99d270496c331b4e50a597135 otherFunctions
## 19: 106559c99d270496c331b4e50a597135 otherFunctions
## 20: 106559c99d270496c331b4e50a597135 preDigest
## 21: 106559c99d270496c331b4e50a597135 preDigest
## 22: 95eb7b563db3ed7ccbdcb4bae23f00f7 format
## 23: 95eb7b563db3ed7ccbdcb4bae23f00f7 name
## 24: 95eb7b563db3ed7ccbdcb4bae23f00f7 class
## 25: 95eb7b563db3ed7ccbdcb4bae23f00f7 date
## 26: 95eb7b563db3ed7ccbdcb4bae23f00f7 cacheId
## 27: 95eb7b563db3ed7ccbdcb4bae23f00f7 objectName
## 28: 95eb7b563db3ed7ccbdcb4bae23f00f7 function
## 29: 95eb7b563db3ed7ccbdcb4bae23f00f7 object.size
## 30: 95eb7b563db3ed7ccbdcb4bae23f00f7 accessed
## 31: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 32: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 33: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 34: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 35: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 36: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 37: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 38: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 39: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 40: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 41: 95eb7b563db3ed7ccbdcb4bae23f00f7 preDigest
## 42: 95eb7b563db3ed7ccbdcb4bae23f00f7 preDigest
## artifact tagKey
## tagValue createdDate
## 1: rda 2019-11-18 06:58:22
## 2: 106559c99d270496c331b4e50a597135 2019-11-18 06:58:22
## 3: numeric 2019-11-18 06:58:22
## 4: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 5: f7bee22047b8d0c1 2019-11-18 06:58:22
## 6: b 2019-11-18 06:58:22
## 7: rnorm 2019-11-18 06:58:22
## 8: 1008 2019-11-18 06:58:22
## 9: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 10: vweave_rmarkdown 2019-11-18 06:58:22
## 11: process_file 2019-11-18 06:58:22
## 12: process_group 2019-11-18 06:58:22
## 13: process_group.block 2019-11-18 06:58:22
## 14: call_block 2019-11-18 06:58:22
## 15: block_exec 2019-11-18 06:58:22
## 16: in_dir 2019-11-18 06:58:22
## 17: timing_fn 2019-11-18 06:58:22
## 18: handle 2019-11-18 06:58:22
## 19: withVisible 2019-11-18 06:58:22
## 20: n:7eef4eae85fd9229 2019-11-18 06:58:22
## 21: .FUN:4f604aa46882b368 2019-11-18 06:58:22
## 22: rda 2019-11-18 06:58:22
## 23: 95eb7b563db3ed7ccbdcb4bae23f00f7 2019-11-18 06:58:22
## 24: numeric 2019-11-18 06:58:22
## 25: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 26: 3aef38d1fc02aee5 2019-11-18 06:58:22
## 27: a 2019-11-18 06:58:22
## 28: runif 2019-11-18 06:58:22
## 29: 1008 2019-11-18 06:58:22
## 30: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 31: vweave_rmarkdown 2019-11-18 06:58:22
## 32: process_file 2019-11-18 06:58:22
## 33: process_group 2019-11-18 06:58:22
## 34: process_group.block 2019-11-18 06:58:22
## 35: call_block 2019-11-18 06:58:22
## 36: block_exec 2019-11-18 06:58:22
## 37: in_dir 2019-11-18 06:58:22
## 38: timing_fn 2019-11-18 06:58:22
## 39: handle 2019-11-18 06:58:22
## 40: withVisible 2019-11-18 06:58:22
## 41: n:7eef4eae85fd9229 2019-11-18 06:58:22
## 42: .FUN:881ec847b7161f3c 2019-11-18 06:58:22
## tagValue createdDate
# show objects that are both runif and rnorm
# (i.e., none in this case, because objecs are either or, not both)
showCache(tmpDir, userTags = c("runif", "rnorm")) ## empty
## Cache size:
## Total (including Rasters): 504 bytes
## Selected objects (not including Rasters): 0 bytes
## Empty data.table (0 rows and 4 cols): artifact,tagKey,tagValue,createdDate
# show objects that are either runif or rnorm ("or" search)
showCache(tmpDir, userTags = "runif|rnorm")
## Cache size:
## Total (including Rasters): 504 bytes
## Selected objects (not including Rasters): 504 bytes
## artifact tagKey
## 1: 106559c99d270496c331b4e50a597135 format
## 2: 106559c99d270496c331b4e50a597135 name
## 3: 106559c99d270496c331b4e50a597135 class
## 4: 106559c99d270496c331b4e50a597135 date
## 5: 106559c99d270496c331b4e50a597135 cacheId
## 6: 106559c99d270496c331b4e50a597135 objectName
## 7: 106559c99d270496c331b4e50a597135 function
## 8: 106559c99d270496c331b4e50a597135 object.size
## 9: 106559c99d270496c331b4e50a597135 accessed
## 10: 106559c99d270496c331b4e50a597135 otherFunctions
## 11: 106559c99d270496c331b4e50a597135 otherFunctions
## 12: 106559c99d270496c331b4e50a597135 otherFunctions
## 13: 106559c99d270496c331b4e50a597135 otherFunctions
## 14: 106559c99d270496c331b4e50a597135 otherFunctions
## 15: 106559c99d270496c331b4e50a597135 otherFunctions
## 16: 106559c99d270496c331b4e50a597135 otherFunctions
## 17: 106559c99d270496c331b4e50a597135 otherFunctions
## 18: 106559c99d270496c331b4e50a597135 otherFunctions
## 19: 106559c99d270496c331b4e50a597135 otherFunctions
## 20: 106559c99d270496c331b4e50a597135 preDigest
## 21: 106559c99d270496c331b4e50a597135 preDigest
## 22: 95eb7b563db3ed7ccbdcb4bae23f00f7 format
## 23: 95eb7b563db3ed7ccbdcb4bae23f00f7 name
## 24: 95eb7b563db3ed7ccbdcb4bae23f00f7 class
## 25: 95eb7b563db3ed7ccbdcb4bae23f00f7 date
## 26: 95eb7b563db3ed7ccbdcb4bae23f00f7 cacheId
## 27: 95eb7b563db3ed7ccbdcb4bae23f00f7 objectName
## 28: 95eb7b563db3ed7ccbdcb4bae23f00f7 function
## 29: 95eb7b563db3ed7ccbdcb4bae23f00f7 object.size
## 30: 95eb7b563db3ed7ccbdcb4bae23f00f7 accessed
## 31: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 32: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 33: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 34: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 35: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 36: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 37: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 38: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 39: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 40: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 41: 95eb7b563db3ed7ccbdcb4bae23f00f7 preDigest
## 42: 95eb7b563db3ed7ccbdcb4bae23f00f7 preDigest
## artifact tagKey
## tagValue createdDate
## 1: rda 2019-11-18 06:58:22
## 2: 106559c99d270496c331b4e50a597135 2019-11-18 06:58:22
## 3: numeric 2019-11-18 06:58:22
## 4: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 5: f7bee22047b8d0c1 2019-11-18 06:58:22
## 6: b 2019-11-18 06:58:22
## 7: rnorm 2019-11-18 06:58:22
## 8: 1008 2019-11-18 06:58:22
## 9: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 10: vweave_rmarkdown 2019-11-18 06:58:22
## 11: process_file 2019-11-18 06:58:22
## 12: process_group 2019-11-18 06:58:22
## 13: process_group.block 2019-11-18 06:58:22
## 14: call_block 2019-11-18 06:58:22
## 15: block_exec 2019-11-18 06:58:22
## 16: in_dir 2019-11-18 06:58:22
## 17: timing_fn 2019-11-18 06:58:22
## 18: handle 2019-11-18 06:58:22
## 19: withVisible 2019-11-18 06:58:22
## 20: n:7eef4eae85fd9229 2019-11-18 06:58:22
## 21: .FUN:4f604aa46882b368 2019-11-18 06:58:22
## 22: rda 2019-11-18 06:58:22
## 23: 95eb7b563db3ed7ccbdcb4bae23f00f7 2019-11-18 06:58:22
## 24: numeric 2019-11-18 06:58:22
## 25: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 26: 3aef38d1fc02aee5 2019-11-18 06:58:22
## 27: a 2019-11-18 06:58:22
## 28: runif 2019-11-18 06:58:22
## 29: 1008 2019-11-18 06:58:22
## 30: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 31: vweave_rmarkdown 2019-11-18 06:58:22
## 32: process_file 2019-11-18 06:58:22
## 33: process_group 2019-11-18 06:58:22
## 34: process_group.block 2019-11-18 06:58:22
## 35: call_block 2019-11-18 06:58:22
## 36: block_exec 2019-11-18 06:58:22
## 37: in_dir 2019-11-18 06:58:22
## 38: timing_fn 2019-11-18 06:58:22
## 39: handle 2019-11-18 06:58:22
## 40: withVisible 2019-11-18 06:58:22
## 41: n:7eef4eae85fd9229 2019-11-18 06:58:22
## 42: .FUN:881ec847b7161f3c 2019-11-18 06:58:22
## tagValue createdDate
# keep only objects that are either runif or rnorm ("or" search)
keepCache(tmpDir, userTags = "runif|rnorm", ask = FALSE)
## Cache size:
## Total (including Rasters): 504 bytes
## Selected objects (not including Rasters): 504 bytes
## artifact tagKey
## 1: 106559c99d270496c331b4e50a597135 format
## 2: 106559c99d270496c331b4e50a597135 name
## 3: 106559c99d270496c331b4e50a597135 class
## 4: 106559c99d270496c331b4e50a597135 date
## 5: 106559c99d270496c331b4e50a597135 cacheId
## 6: 106559c99d270496c331b4e50a597135 objectName
## 7: 106559c99d270496c331b4e50a597135 function
## 8: 106559c99d270496c331b4e50a597135 object.size
## 9: 106559c99d270496c331b4e50a597135 accessed
## 10: 106559c99d270496c331b4e50a597135 otherFunctions
## 11: 106559c99d270496c331b4e50a597135 otherFunctions
## 12: 106559c99d270496c331b4e50a597135 otherFunctions
## 13: 106559c99d270496c331b4e50a597135 otherFunctions
## 14: 106559c99d270496c331b4e50a597135 otherFunctions
## 15: 106559c99d270496c331b4e50a597135 otherFunctions
## 16: 106559c99d270496c331b4e50a597135 otherFunctions
## 17: 106559c99d270496c331b4e50a597135 otherFunctions
## 18: 106559c99d270496c331b4e50a597135 otherFunctions
## 19: 106559c99d270496c331b4e50a597135 otherFunctions
## 20: 106559c99d270496c331b4e50a597135 preDigest
## 21: 106559c99d270496c331b4e50a597135 preDigest
## 22: 95eb7b563db3ed7ccbdcb4bae23f00f7 format
## 23: 95eb7b563db3ed7ccbdcb4bae23f00f7 name
## 24: 95eb7b563db3ed7ccbdcb4bae23f00f7 class
## 25: 95eb7b563db3ed7ccbdcb4bae23f00f7 date
## 26: 95eb7b563db3ed7ccbdcb4bae23f00f7 cacheId
## 27: 95eb7b563db3ed7ccbdcb4bae23f00f7 objectName
## 28: 95eb7b563db3ed7ccbdcb4bae23f00f7 function
## 29: 95eb7b563db3ed7ccbdcb4bae23f00f7 object.size
## 30: 95eb7b563db3ed7ccbdcb4bae23f00f7 accessed
## 31: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 32: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 33: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 34: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 35: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 36: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 37: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 38: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 39: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 40: 95eb7b563db3ed7ccbdcb4bae23f00f7 otherFunctions
## 41: 95eb7b563db3ed7ccbdcb4bae23f00f7 preDigest
## 42: 95eb7b563db3ed7ccbdcb4bae23f00f7 preDigest
## artifact tagKey
## tagValue createdDate
## 1: rda 2019-11-18 06:58:22
## 2: 106559c99d270496c331b4e50a597135 2019-11-18 06:58:22
## 3: numeric 2019-11-18 06:58:22
## 4: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 5: f7bee22047b8d0c1 2019-11-18 06:58:22
## 6: b 2019-11-18 06:58:22
## 7: rnorm 2019-11-18 06:58:22
## 8: 1008 2019-11-18 06:58:22
## 9: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 10: vweave_rmarkdown 2019-11-18 06:58:22
## 11: process_file 2019-11-18 06:58:22
## 12: process_group 2019-11-18 06:58:22
## 13: process_group.block 2019-11-18 06:58:22
## 14: call_block 2019-11-18 06:58:22
## 15: block_exec 2019-11-18 06:58:22
## 16: in_dir 2019-11-18 06:58:22
## 17: timing_fn 2019-11-18 06:58:22
## 18: handle 2019-11-18 06:58:22
## 19: withVisible 2019-11-18 06:58:22
## 20: n:7eef4eae85fd9229 2019-11-18 06:58:22
## 21: .FUN:4f604aa46882b368 2019-11-18 06:58:22
## 22: rda 2019-11-18 06:58:22
## 23: 95eb7b563db3ed7ccbdcb4bae23f00f7 2019-11-18 06:58:22
## 24: numeric 2019-11-18 06:58:22
## 25: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 26: 3aef38d1fc02aee5 2019-11-18 06:58:22
## 27: a 2019-11-18 06:58:22
## 28: runif 2019-11-18 06:58:22
## 29: 1008 2019-11-18 06:58:22
## 30: 2019-11-18 06:58:22 2019-11-18 06:58:22
## 31: vweave_rmarkdown 2019-11-18 06:58:22
## 32: process_file 2019-11-18 06:58:22
## 33: process_group 2019-11-18 06:58:22
## 34: process_group.block 2019-11-18 06:58:22
## 35: call_block 2019-11-18 06:58:22
## 36: block_exec 2019-11-18 06:58:22
## 37: in_dir 2019-11-18 06:58:22
## 38: timing_fn 2019-11-18 06:58:22
## 39: handle 2019-11-18 06:58:22
## 40: withVisible 2019-11-18 06:58:22
## 41: n:7eef4eae85fd9229 2019-11-18 06:58:22
## 42: .FUN:881ec847b7161f3c 2019-11-18 06:58:22
## tagValue createdDate
ras <- raster(extent(0, 5, 0, 5), res = 1,
vals = sample(1:5, replace = TRUE, size = 25),
crs = "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +ellps=WGS84")
# A slow operation, like GIS operation
notCached <- suppressWarnings(
# project raster generates warnings when run non-interactively
projectRaster(ras, crs = crs(ras), res = 5, cacheRepo = tmpDir)
)
cached <- suppressWarnings(
# project raster generates warnings when run non-interactively
# using quote works also
Cache(projectRaster, ras, crs = crs(ras), res = 5, cacheRepo = tmpDir)
)
# second time is much faster
reRun <- suppressWarnings(
# project raster generates warnings when run non-interactively
Cache(projectRaster, ras, crs = crs(ras), res = 5, cacheRepo = tmpDir)
)
## loading cached result from previous projectRaster call, adding to memoised copy
## [1] TRUE
Nested caching, which is when Caching of a function occurs inside an outer function, which is itself cached. This is a critical element to working within a reproducible work flow. It is not enough during development to cache flat code chunks, as there will be many levels of “slow” functions. Ideally, at all points in a development cycle, it should be possible to get to any line of code starting from the very initial steps, running through everything up to that point, in less that 1 second. If the workflow can be kept very fast like this, then there is a guarantee that it will work at any point.
##########################
## Nested Caching
# Make 2 functions
inner <- function(mean) {
d <- 1
Cache(rnorm, n = 3, mean = mean)
}
outer <- function(n) {
Cache(inner, 0.1, cacheRepo = tmpdir2)
}
# make 2 different cache paths
tmpdir1 <- file.path(tempdir(), "first")
tmpdir2 <- file.path(tempdir(), "second")
# Run the Cache ... notOlderThan propagates to all 3 Cache calls,
# but cacheRepo is tmpdir1 in top level Cache and all nested
# Cache calls, unless individually overridden ... here inner
# uses tmpdir2 repository
Cache(outer, n = 2, cacheRepo = tmpdir1, notOlderThan = Sys.time())
## [1] -0.7060652 -1.3127788 -0.3790895
## attr(,".Cache")
## attr(,".Cache")$newCache
## [1] TRUE
##
## attr(,"tags")
## [1] "cacheId:a7af5367c13aba8f"
## attr(,"call")
## [1] ""
## Cache size:
## Total (including Rasters): 504 bytes
## Selected objects (not including Rasters): 504 bytes
## artifact tagKey
## 1: 168921ebe4d5ca61a7210618a190e512 format
## 2: 168921ebe4d5ca61a7210618a190e512 name
## 3: 168921ebe4d5ca61a7210618a190e512 class
## 4: 168921ebe4d5ca61a7210618a190e512 date
## 5: 168921ebe4d5ca61a7210618a190e512 cacheId
## 6: 168921ebe4d5ca61a7210618a190e512 function
## 7: 168921ebe4d5ca61a7210618a190e512 object.size
## 8: 168921ebe4d5ca61a7210618a190e512 accessed
## 9: 168921ebe4d5ca61a7210618a190e512 otherFunctions
## 10: 168921ebe4d5ca61a7210618a190e512 otherFunctions
## 11: 168921ebe4d5ca61a7210618a190e512 otherFunctions
## 12: 168921ebe4d5ca61a7210618a190e512 otherFunctions
## 13: 168921ebe4d5ca61a7210618a190e512 otherFunctions
## 14: 168921ebe4d5ca61a7210618a190e512 otherFunctions
## 15: 168921ebe4d5ca61a7210618a190e512 otherFunctions
## 16: 168921ebe4d5ca61a7210618a190e512 otherFunctions
## 17: 168921ebe4d5ca61a7210618a190e512 otherFunctions
## 18: 168921ebe4d5ca61a7210618a190e512 otherFunctions
## 19: 168921ebe4d5ca61a7210618a190e512 preDigest
## 20: 168921ebe4d5ca61a7210618a190e512 preDigest
## 21: 168921ebe4d5ca61a7210618a190e512 preDigest
## 22: a441ef97515c69501a6c23e15d93d169 format
## 23: a441ef97515c69501a6c23e15d93d169 name
## 24: a441ef97515c69501a6c23e15d93d169 class
## 25: a441ef97515c69501a6c23e15d93d169 date
## 26: a441ef97515c69501a6c23e15d93d169 cacheId
## 27: a441ef97515c69501a6c23e15d93d169 function
## 28: a441ef97515c69501a6c23e15d93d169 object.size
## 29: a441ef97515c69501a6c23e15d93d169 accessed
## 30: a441ef97515c69501a6c23e15d93d169 otherFunctions
## 31: a441ef97515c69501a6c23e15d93d169 otherFunctions
## 32: a441ef97515c69501a6c23e15d93d169 otherFunctions
## 33: a441ef97515c69501a6c23e15d93d169 otherFunctions
## 34: a441ef97515c69501a6c23e15d93d169 otherFunctions
## 35: a441ef97515c69501a6c23e15d93d169 otherFunctions
## 36: a441ef97515c69501a6c23e15d93d169 otherFunctions
## 37: a441ef97515c69501a6c23e15d93d169 otherFunctions
## 38: a441ef97515c69501a6c23e15d93d169 otherFunctions
## 39: a441ef97515c69501a6c23e15d93d169 otherFunctions
## 40: a441ef97515c69501a6c23e15d93d169 preDigest
## 41: a441ef97515c69501a6c23e15d93d169 preDigest
## artifact tagKey
## tagValue createdDate
## 1: rda 2019-11-18 06:58:23
## 2: 168921ebe4d5ca61a7210618a190e512 2019-11-18 06:58:23
## 3: numeric 2019-11-18 06:58:23
## 4: 2019-11-18 06:58:23 2019-11-18 06:58:23
## 5: 4ac2b7c0f42d1e46 2019-11-18 06:58:23
## 6: rnorm 2019-11-18 06:58:23
## 7: 1008 2019-11-18 06:58:23
## 8: 2019-11-18 06:58:23 2019-11-18 06:58:23
## 9: vweave_rmarkdown 2019-11-18 06:58:23
## 10: process_file 2019-11-18 06:58:23
## 11: process_group 2019-11-18 06:58:23
## 12: process_group.block 2019-11-18 06:58:23
## 13: call_block 2019-11-18 06:58:23
## 14: block_exec 2019-11-18 06:58:23
## 15: in_dir 2019-11-18 06:58:23
## 16: timing_fn 2019-11-18 06:58:23
## 17: handle 2019-11-18 06:58:23
## 18: withVisible 2019-11-18 06:58:23
## 19: n:7f12988bd88a0fb8 2019-11-18 06:58:23
## 20: mean:22413394efd9f6a3 2019-11-18 06:58:23
## 21: .FUN:4f604aa46882b368 2019-11-18 06:58:23
## 22: rda 2019-11-18 06:58:23
## 23: a441ef97515c69501a6c23e15d93d169 2019-11-18 06:58:23
## 24: numeric 2019-11-18 06:58:23
## 25: 2019-11-18 06:58:23 2019-11-18 06:58:23
## 26: a7af5367c13aba8f 2019-11-18 06:58:23
## 27: outer 2019-11-18 06:58:23
## 28: 1008 2019-11-18 06:58:23
## 29: 2019-11-18 06:58:23 2019-11-18 06:58:23
## 30: vweave_rmarkdown 2019-11-18 06:58:23
## 31: process_file 2019-11-18 06:58:23
## 32: process_group 2019-11-18 06:58:23
## 33: process_group.block 2019-11-18 06:58:23
## 34: call_block 2019-11-18 06:58:23
## 35: block_exec 2019-11-18 06:58:23
## 36: in_dir 2019-11-18 06:58:23
## 37: timing_fn 2019-11-18 06:58:23
## 38: handle 2019-11-18 06:58:23
## 39: withVisible 2019-11-18 06:58:23
## 40: n:82dc709f2b91918a 2019-11-18 06:58:23
## 41: .FUN:892a6afc47a63a90 2019-11-18 06:58:23
## tagValue createdDate
## Cache size:
## Total (including Rasters): 252 bytes
## Selected objects (not including Rasters): 252 bytes
## artifact tagKey
## 1: 8e37b3bffeb6257415bf3c921e05c54d format
## 2: 8e37b3bffeb6257415bf3c921e05c54d name
## 3: 8e37b3bffeb6257415bf3c921e05c54d class
## 4: 8e37b3bffeb6257415bf3c921e05c54d date
## 5: 8e37b3bffeb6257415bf3c921e05c54d cacheId
## 6: 8e37b3bffeb6257415bf3c921e05c54d function
## 7: 8e37b3bffeb6257415bf3c921e05c54d object.size
## 8: 8e37b3bffeb6257415bf3c921e05c54d accessed
## 9: 8e37b3bffeb6257415bf3c921e05c54d otherFunctions
## 10: 8e37b3bffeb6257415bf3c921e05c54d otherFunctions
## 11: 8e37b3bffeb6257415bf3c921e05c54d otherFunctions
## 12: 8e37b3bffeb6257415bf3c921e05c54d otherFunctions
## 13: 8e37b3bffeb6257415bf3c921e05c54d otherFunctions
## 14: 8e37b3bffeb6257415bf3c921e05c54d otherFunctions
## 15: 8e37b3bffeb6257415bf3c921e05c54d otherFunctions
## 16: 8e37b3bffeb6257415bf3c921e05c54d otherFunctions
## 17: 8e37b3bffeb6257415bf3c921e05c54d otherFunctions
## 18: 8e37b3bffeb6257415bf3c921e05c54d otherFunctions
## 19: 8e37b3bffeb6257415bf3c921e05c54d preDigest
## 20: 8e37b3bffeb6257415bf3c921e05c54d preDigest
## tagValue createdDate
## 1: rda 2019-11-18 06:58:23
## 2: 8e37b3bffeb6257415bf3c921e05c54d 2019-11-18 06:58:23
## 3: numeric 2019-11-18 06:58:23
## 4: 2019-11-18 06:58:23 2019-11-18 06:58:23
## 5: 33ceb4fb525fd08f 2019-11-18 06:58:23
## 6: inner 2019-11-18 06:58:23
## 7: 1008 2019-11-18 06:58:23
## 8: 2019-11-18 06:58:23 2019-11-18 06:58:23
## 9: vweave_rmarkdown 2019-11-18 06:58:23
## 10: process_file 2019-11-18 06:58:23
## 11: process_group 2019-11-18 06:58:23
## 12: process_group.block 2019-11-18 06:58:23
## 13: call_block 2019-11-18 06:58:23
## 14: block_exec 2019-11-18 06:58:23
## 15: in_dir 2019-11-18 06:58:23
## 16: timing_fn 2019-11-18 06:58:23
## 17: handle 2019-11-18 06:58:23
## 18: withVisible 2019-11-18 06:58:23
## 19: mean:22413394efd9f6a3 2019-11-18 06:58:23
## 20: .FUN:87e2c30917a34d25 2019-11-18 06:58:23
# userTags get appended
# all items have the outer tag propagate, plus inner ones only have inner ones
clearCache(tmpdir1, ask = FALSE)
outerTag <- "outerTag"
innerTag <- "innerTag"
inner <- function(mean) {
d <- 1
Cache(rnorm, n = 3, mean = mean, notOlderThan = Sys.time() - 1e5, userTags = innerTag)
}
outer <- function(n) {
Cache(inner, 0.1)
}
aa <- Cache(outer, n = 2, cacheRepo = tmpdir1, userTags = outerTag)
showCache(tmpdir1) # rnorm function has outerTag and innerTag, inner and outer only have outerTag
## Cache size:
## Total (including Rasters): 756 bytes
## Selected objects (not including Rasters): 756 bytes
## artifact tagKey
## 1: 1abdd84da8f62e178e8301d3170254ec format
## 2: 1abdd84da8f62e178e8301d3170254ec name
## 3: 1abdd84da8f62e178e8301d3170254ec class
## 4: 1abdd84da8f62e178e8301d3170254ec date
## 5: 1abdd84da8f62e178e8301d3170254ec cacheId
## 6: 1abdd84da8f62e178e8301d3170254ec outerTag
## 7: 1abdd84da8f62e178e8301d3170254ec function
## 8: 1abdd84da8f62e178e8301d3170254ec object.size
## 9: 1abdd84da8f62e178e8301d3170254ec accessed
## 10: 1abdd84da8f62e178e8301d3170254ec otherFunctions
## 11: 1abdd84da8f62e178e8301d3170254ec otherFunctions
## 12: 1abdd84da8f62e178e8301d3170254ec otherFunctions
## 13: 1abdd84da8f62e178e8301d3170254ec otherFunctions
## 14: 1abdd84da8f62e178e8301d3170254ec otherFunctions
## 15: 1abdd84da8f62e178e8301d3170254ec otherFunctions
## 16: 1abdd84da8f62e178e8301d3170254ec otherFunctions
## 17: 1abdd84da8f62e178e8301d3170254ec otherFunctions
## 18: 1abdd84da8f62e178e8301d3170254ec otherFunctions
## 19: 1abdd84da8f62e178e8301d3170254ec otherFunctions
## 20: 1abdd84da8f62e178e8301d3170254ec preDigest
## 21: 1abdd84da8f62e178e8301d3170254ec preDigest
## 22: 89f8572e8d8df9259ff4ecdcfeedac1c format
## 23: 89f8572e8d8df9259ff4ecdcfeedac1c name
## 24: 89f8572e8d8df9259ff4ecdcfeedac1c class
## 25: 89f8572e8d8df9259ff4ecdcfeedac1c date
## 26: 89f8572e8d8df9259ff4ecdcfeedac1c cacheId
## 27: 89f8572e8d8df9259ff4ecdcfeedac1c outerTag
## 28: 89f8572e8d8df9259ff4ecdcfeedac1c function
## 29: 89f8572e8d8df9259ff4ecdcfeedac1c object.size
## 30: 89f8572e8d8df9259ff4ecdcfeedac1c accessed
## 31: 89f8572e8d8df9259ff4ecdcfeedac1c otherFunctions
## 32: 89f8572e8d8df9259ff4ecdcfeedac1c otherFunctions
## 33: 89f8572e8d8df9259ff4ecdcfeedac1c otherFunctions
## 34: 89f8572e8d8df9259ff4ecdcfeedac1c otherFunctions
## 35: 89f8572e8d8df9259ff4ecdcfeedac1c otherFunctions
## 36: 89f8572e8d8df9259ff4ecdcfeedac1c otherFunctions
## 37: 89f8572e8d8df9259ff4ecdcfeedac1c otherFunctions
## 38: 89f8572e8d8df9259ff4ecdcfeedac1c otherFunctions
## 39: 89f8572e8d8df9259ff4ecdcfeedac1c otherFunctions
## 40: 89f8572e8d8df9259ff4ecdcfeedac1c otherFunctions
## 41: 89f8572e8d8df9259ff4ecdcfeedac1c preDigest
## 42: 89f8572e8d8df9259ff4ecdcfeedac1c preDigest
## 43: d44b541c95c73f8b0fc4102d4ac2fcbf format
## 44: d44b541c95c73f8b0fc4102d4ac2fcbf name
## 45: d44b541c95c73f8b0fc4102d4ac2fcbf class
## 46: d44b541c95c73f8b0fc4102d4ac2fcbf date
## 47: d44b541c95c73f8b0fc4102d4ac2fcbf cacheId
## 48: d44b541c95c73f8b0fc4102d4ac2fcbf innerTag
## 49: d44b541c95c73f8b0fc4102d4ac2fcbf outerTag
## 50: d44b541c95c73f8b0fc4102d4ac2fcbf function
## 51: d44b541c95c73f8b0fc4102d4ac2fcbf object.size
## 52: d44b541c95c73f8b0fc4102d4ac2fcbf accessed
## 53: d44b541c95c73f8b0fc4102d4ac2fcbf otherFunctions
## 54: d44b541c95c73f8b0fc4102d4ac2fcbf otherFunctions
## 55: d44b541c95c73f8b0fc4102d4ac2fcbf otherFunctions
## 56: d44b541c95c73f8b0fc4102d4ac2fcbf otherFunctions
## 57: d44b541c95c73f8b0fc4102d4ac2fcbf otherFunctions
## 58: d44b541c95c73f8b0fc4102d4ac2fcbf otherFunctions
## 59: d44b541c95c73f8b0fc4102d4ac2fcbf otherFunctions
## 60: d44b541c95c73f8b0fc4102d4ac2fcbf otherFunctions
## 61: d44b541c95c73f8b0fc4102d4ac2fcbf otherFunctions
## 62: d44b541c95c73f8b0fc4102d4ac2fcbf otherFunctions
## 63: d44b541c95c73f8b0fc4102d4ac2fcbf preDigest
## 64: d44b541c95c73f8b0fc4102d4ac2fcbf preDigest
## 65: d44b541c95c73f8b0fc4102d4ac2fcbf preDigest
## artifact tagKey
## tagValue createdDate
## 1: rda 2019-11-18 06:58:24
## 2: 1abdd84da8f62e178e8301d3170254ec 2019-11-18 06:58:24
## 3: numeric 2019-11-18 06:58:24
## 4: 2019-11-18 06:58:24 2019-11-18 06:58:24
## 5: 88a34e1d033329e5 2019-11-18 06:58:24
## 6: outerTag 2019-11-18 06:58:24
## 7: outer 2019-11-18 06:58:24
## 8: 1008 2019-11-18 06:58:24
## 9: 2019-11-18 06:58:24 2019-11-18 06:58:24
## 10: vweave_rmarkdown 2019-11-18 06:58:24
## 11: process_file 2019-11-18 06:58:24
## 12: process_group 2019-11-18 06:58:24
## 13: process_group.block 2019-11-18 06:58:24
## 14: call_block 2019-11-18 06:58:24
## 15: block_exec 2019-11-18 06:58:24
## 16: in_dir 2019-11-18 06:58:24
## 17: timing_fn 2019-11-18 06:58:24
## 18: handle 2019-11-18 06:58:24
## 19: withVisible 2019-11-18 06:58:24
## 20: n:82dc709f2b91918a 2019-11-18 06:58:24
## 21: .FUN:5f06fb5fbffe9e3b 2019-11-18 06:58:24
## 22: rda 2019-11-18 06:58:24
## 23: 89f8572e8d8df9259ff4ecdcfeedac1c 2019-11-18 06:58:24
## 24: numeric 2019-11-18 06:58:24
## 25: 2019-11-18 06:58:24 2019-11-18 06:58:24
## 26: b06af03d5a73dc7d 2019-11-18 06:58:24
## 27: outerTag 2019-11-18 06:58:24
## 28: inner 2019-11-18 06:58:24
## 29: 1008 2019-11-18 06:58:24
## 30: 2019-11-18 06:58:24 2019-11-18 06:58:24
## 31: vweave_rmarkdown 2019-11-18 06:58:24
## 32: process_file 2019-11-18 06:58:24
## 33: process_group 2019-11-18 06:58:24
## 34: process_group.block 2019-11-18 06:58:24
## 35: call_block 2019-11-18 06:58:24
## 36: block_exec 2019-11-18 06:58:24
## 37: in_dir 2019-11-18 06:58:24
## 38: timing_fn 2019-11-18 06:58:24
## 39: handle 2019-11-18 06:58:24
## 40: withVisible 2019-11-18 06:58:24
## 41: mean:22413394efd9f6a3 2019-11-18 06:58:24
## 42: .FUN:7ad10bc1ae528d8c 2019-11-18 06:58:24
## 43: rda 2019-11-18 06:58:24
## 44: d44b541c95c73f8b0fc4102d4ac2fcbf 2019-11-18 06:58:24
## 45: numeric 2019-11-18 06:58:24
## 46: 2019-11-18 06:58:24 2019-11-18 06:58:24
## 47: 4ac2b7c0f42d1e46 2019-11-18 06:58:24
## 48: innerTag 2019-11-18 06:58:24
## 49: outerTag 2019-11-18 06:58:24
## 50: rnorm 2019-11-18 06:58:24
## 51: 1008 2019-11-18 06:58:24
## 52: 2019-11-18 06:58:24 2019-11-18 06:58:24
## 53: vweave_rmarkdown 2019-11-18 06:58:24
## 54: process_file 2019-11-18 06:58:24
## 55: process_group 2019-11-18 06:58:24
## 56: process_group.block 2019-11-18 06:58:24
## 57: call_block 2019-11-18 06:58:24
## 58: block_exec 2019-11-18 06:58:24
## 59: in_dir 2019-11-18 06:58:24
## 60: timing_fn 2019-11-18 06:58:24
## 61: handle 2019-11-18 06:58:24
## 62: withVisible 2019-11-18 06:58:24
## 63: n:7f12988bd88a0fb8 2019-11-18 06:58:24
## 64: mean:22413394efd9f6a3 2019-11-18 06:58:24
## 65: .FUN:4f604aa46882b368 2019-11-18 06:58:24
## tagValue createdDate
Sometimes, it is not absolutely desirable to maintain the work flow intact because changes that are irrelevant to the analysis, such as changing messages sent to a user, may be changed, without a desire to rerun functions. The cacheId
argument is for this. Once a piece of code is run, then the cacheId
can be manually extracted (it is reported at the end of a Cache call) and manually placed in the code, passed in as, say, cacheId = "ad184ce64541972b50afd8e7b75f821b"
.
## [1] -0.6264538
## attr(,".Cache")
## attr(,".Cache")$newCache
## [1] TRUE
##
## attr(,"tags")
## [1] "cacheId:7072c305d8c69df0"
## attr(,"call")
## [1] ""
# manually look at output attribute which shows cacheId: ad184ce64541972b50afd8e7b75f821b
Cache(rnorm, 1, cacheRepo = tmpdir1, cacheId = "ad184ce64541972b50afd8e7b75f821b") # same value
## cacheId is not same as calculated hash. Manually searching for cacheId:ad184ce64541972b50afd8e7b75f821b
## [1] 0.1836433
## attr(,".Cache")
## attr(,".Cache")$newCache
## [1] TRUE
##
## attr(,"tags")
## [1] "cacheId:ad184ce64541972b50afd8e7b75f821b"
## attr(,"call")
## [1] ""
# override even with different inputs:
Cache(rnorm, 2, cacheRepo = tmpdir1, cacheId = "ad184ce64541972b50afd8e7b75f821b")
## cacheId is not same as calculated hash. Manually searching for cacheId:ad184ce64541972b50afd8e7b75f821b
## loading cached result from previous rnorm call, adding to memoised copy
## [1] 0.1836433
## attr(,".Cache")
## attr(,".Cache")$newCache
## [1] FALSE
##
## attr(,"tags")
## [1] "cacheId:ad184ce64541972b50afd8e7b75f821b"
## attr(,"call")
## [1] ""
Since the cache is simply an archivist
repository, all archivist
functions will work as is. In addition, there are several helpers in the reproducible
package, including showCache
, keepCache
and clearCache
that may be useful. Also, one can access cached items manually (rather than simply rerunning the same Cache
function again).
if (requireNamespace("archivist")) {
# get the RasterLayer that was produced with the gaussMap function:
mapHash <- unique(showCache(tmpDir, userTags = "projectRaster")$artifact)
map <- archivist::loadFromLocalRepo(md5hash = mapHash[1], repoDir = tmpDir, value = TRUE)
plot(map)
}
## Cache size:
## Total (including Rasters): 3.3 Kb
## Selected objects (not including Rasters): 3.3 Kb
In general, we feel that a liberal use of Cache
will make a re-usable and reproducible work flow. shiny
apps can be made, taking advantage of Cache
. Indeed, much of the difficulty in managing data sets and saving them for future use, can be accommodated by caching.
Cache(<functionName>, <other arguments>)
This will allow fine scale control of individual function calls.