R/get_data.R

Defines functions get_data

Documented in get_data

#' Get data
#' 
#' Download remote resources stored on GitHub Releases via \pkg{piggyback}.
#' 
#' @param fname File name.
#' @param repo GitHub repository name.
#' @param save_dir Local directory to cache data in.
#' @inheritParams piggyback::pb_download
#' @inheritDotParams piggyback::pb_download
#' 
#' @export
#' @importFrom piggyback pb_download
#' @importFrom tools R_user_dir
#' @examples 
#' tmp <- get_data(fname = "Kunkle2019.tsv.gz")
get_data <- function(fname,
                     repo = "RajLabMSSM/echodata",
                     save_dir = tools::R_user_dir(package = "echodata",
                                                  which = "cache"),
                     overwrite = FALSE,
                     tag = "latest",
                     ...){
    
    tmp <- file.path(save_dir,fname)
    if(!file.exists(tmp)){
        Sys.setenv("piggyback_cache_duration"=10)
        dir.create(save_dir,showWarnings = FALSE, recursive = TRUE)
        piggyback::pb_download(file = fname,
                               dest = save_dir,
                               repo = repo, 
                               tag = tag,
                               overwrite = overwrite,
                               ...)
    }
    return(tmp)
}
RajLabMSSM/echodata documentation built on Nov. 21, 2023, 8 a.m.