grapes-cache_df-grapes: Tries reading a cached dataframe result from the filename on...

%cache_df%R Documentation

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.

Description

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.

Usage

call %cache_df% fname

Arguments

call

function call

fname

filename

Examples

temp_file <- tempfile(fileext = ".tsv")
calc_mtcars_cyl <- function(cyl) {
    message("calculating")
    as.data.frame(mtcars[mtcars$cyl == cyl, ])
}

# Call "calc_mtcars_cyl" function
res1 <- calc_mtcars_cyl(6) %cache_df% temp_file

# Load cached file
res2 <- calc_mtcars_cyl(6) %cache_df% temp_file

tanaylab/tgutil documentation built on March 16, 2024, 12:07 a.m.