R/io.R
grapes-cache_rds-grapes.Rd
Tries reading a cached dataframe result from the filename on the right side. If the file is missing, generate the dataframe 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_rds% fname
function call
filename
temp_file <- tempfile(fileext = "rds")
calc_mtcars_cyl <- function(cyl) {
message("calculating")
mtcars[mtcars$cyl == cyl, ]
}
# Call "calc_mtcars_cyl" function
res1 <- calc_mtcars_cyl(6) %cache_rds% temp_file
#> calculating
# Load cached file
res2 <- calc_mtcars_cyl(6) %cache_rds% temp_file
#> Using cached rds from '/tmp/RtmpISImil/file16776291a6db2rds'