Skip to content

Instantly share code, notes, and snippets.

@bmschmidt
Forked from zkamvar/lazierLoad.R
Last active September 11, 2015 16:35
Show Gist options
  • Save bmschmidt/a73b1c555897841f4b8e to your computer and use it in GitHub Desktop.
Save bmschmidt/a73b1c555897841f4b8e to your computer and use it in GitHub Desktop.
Does a lazy load across all files when provided a knitr cache directory.
#' Performs lazy load on a directory
#'
#' @param path a filepath containing the necessary files for lazy loading
#' @return NULL
#'
#' @details This function will go into a directory, search for all the files
#' that seem like they can be lazily loaded and attempt to load them.
#'
lazierLoad <- function(path){
files <- dir(path)
cache_files <- sub(".rdb$", "", files[grepl(".rdb$", files)])
for (i in cache_files) try(lazyLoad(paste(path, i, sep = "/"), envir = .GlobalEnv))
}
laziestLoad <- function(path=".") {
files <- list.files(path,recursive=TRUE)
cache_files <- sub(".rdb$", "", files[grepl(".rdb$", files)])
for (i in cache_files) try(lazyLoad(i, envir = .GlobalEnv))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment