#' Mangle the knitr cache path so that it doesn't sync on Box
#'
#' @param cache_path initial cache path
#'
#' @return side-effect of altering knitr cache_path and the new path invisibly
#' @export
mangle_cache_path = function(cache_path = knitr::opts_chunk$get()$cache.path){
cps = strsplit(cache_path, '[/:\\]')[[1]]
if(length(cps) != 2) stop('Expecting rmarkdown cache set up')
cps[[1]] = paste0('~', cps[[1]])
cps_mangle = do.call(file.path, as.list(cps))
knitr::opts_chunk$set(cache.path = cps_mangle)
invisible(cps_mangle)
}
#' Shortcut for rmarkdown::render that preserves intermediates
#'
#' @param ... passed to rmarkdown
#' @param envir The environment in which the code chunks are to be evaluated during knitting (can use new.env() to guarantee an empty new environment).
#' @param clean TRUE to clean intermediate files created during rendering.
#' @return When run_pandoc = TRUE, the compiled document is written into the output file, and the path of the output file is returned.
#' When run_pandoc = FALSE, the path of the Markdown output file, with attributes knit_meta (the knitr meta data collected from code chunks) and intermediates (the intermediate files/directories generated by render()).
#' @export
rrndr <- function(..., envir = parent.frame(), clean = FALSE){
rmarkdown::render(..., clean = clean, envir = envir)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.