%cache_matrix% | R Documentation |
Tries reading a cached matrix result from the filename on the right side. If the file is missing, generate the matrix using the function call on the left side and write the result to the file. If "tgutil.cache" option is FALSE, right side would be always recumputed.
call %cache_matrix% fname
call |
function call |
fname |
filename |
temp_file <- tempfile(fileext = ".tsv")
calc_mtcars_cyl <- function(cyl) {
message("calculating")
as.matrix(mtcars[mtcars$cyl == cyl, ])
}
# Call "calc_mtcars_cyl" function
res1 <- calc_mtcars_cyl(6) %cache_matrix% temp_file
# Load cached file
res2 <- calc_mtcars_cyl(6) %cache_matrix% temp_file
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.