cache_to_filearray | R Documentation |
Avoid repeating yourself
cache_to_filearray(
fun,
filebase,
globals,
dimension,
type = "auto",
partition_size = 1L,
verbose = FALSE,
...
)
fun |
function that can be called with no mandatory arguments; the result should be in a matrix or an array |
filebase |
where to store the array |
globals |
names of variables such that any changes
should trigger a new evaluation of |
dimension |
what is the supposed dimension, default is automatically calculated from array. If specified explicitly and the file array dimension is inconsistent, a new calculation will be triggered. |
type |
file array type, default is |
partition_size |
file array partition size; default is |
verbose |
whether to verbose debug information |
... |
passed to |
c <- 2
b <- list(d = matrix(1:9,3))
filebase <- tempfile()
f <- function() {
message("New calculation")
re <- c + b$d
dimnames(re) <- list(A=1:3, B = 11:13)
# `extra` attribute will be saved
attr(re, "extra") <- "extra meta data"
re
}
# first time running
arr <- cache_to_filearray( f, filebase = filebase )
# cached, no re-run
arr <- cache_to_filearray( f, filebase = filebase )
# file array object
arr
# read into memory
arr[]
# read extra data
arr$get_header("extra")
# get digest results
arr$get_header("raveio::filearray_cache")
## Clean up this example
unlink(filebase, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.