Last active
December 22, 2017 09:02
-
-
Save achateigner/e3f905d9fc98d34c8ecee93275c80a07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loadAllChunksCache <- function(fileContainingChunks, | |
pathForCache = paste0(sub(".Rmd", "", fileContainingChunks), | |
"_cache/", | |
names(which(sapply(c("html", "pdf", "word"), | |
function(x)dir.exists(paste0(sub(".Rmd", "", fileContainingChunks), "_cache/", x, "/")))))[1], | |
"/")){ | |
lignesDeNomDeChunk <- grep("^```{r", readLines(fileContainingChunks), perl = TRUE, value = TRUE) | |
nomsDeChunks <- sapply(strsplit( | |
sapply(strsplit( | |
sapply(strsplit(lignesDeNomDeChunk, "{r ", perl = TRUE), function(x) x[[2]]), | |
","), function(y) y[[1]]), | |
"}"), function(z) z[[1]]) | |
chunkFiles <- unlist(lapply(1:length(nomsDeChunks), function(i){ | |
fichier <- list.files(path=pathForCache, pattern=paste0("^", nomsDeChunks[i]), full.names = TRUE) | |
if (length(fichier) >= 1){ | |
names(fichier) <- nomsDeChunks[i] | |
return(fichier) | |
} | |
})) | |
for (j in chunkFiles){ | |
message(j) | |
get(load(j, .GlobalEnv)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment