diff --git a/NEWS b/NEWS index 2b3bff09..6f633e6c 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,9 @@ htmltools 0.3.6.9003 * The error message for trailing commas in tag functions now provides context and useful information. (#109) +* Adds the ability to skip overwriting existing html dependencies in the function copyDependenciesToDir. Intended to be used with +rmarkdown::render to speed up rendering. + htmltools 0.3.6 -------------------------------------------------------------------------------- diff --git a/R/html_dependency.R b/R/html_dependency.R index 9db94058..34538ada 100644 --- a/R/html_dependency.R +++ b/R/html_dependency.R @@ -252,6 +252,7 @@ urlEncodePath <- function(x) { #' @param dependency A single HTML dependency object. #' @param outputDir The directory in which a subdirectory should be created for #' this dependency. +#' @param overwrite_dir A logical indicating whether the dependency should be overwritten if it exists, defaults to \code{TRUE}. #' @param mustWork If \code{TRUE} and \code{dependency} does not point to a #' directory on disk (but rather a URL location), an error is raised. If #' \code{FALSE} then non-disk dependencies are returned without modification. @@ -263,7 +264,7 @@ urlEncodePath <- function(x) { #' value to make the path relative to a specific directory. #' #' @export -copyDependencyToDir <- function(dependency, outputDir, mustWork = TRUE) { +copyDependencyToDir <- function(dependency, outputDir, mustWork = TRUE, overwrite_dir = TRUE) { dir <- dependency$src$file @@ -290,6 +291,12 @@ copyDependencyToDir <- function(dependency, outputDir, mustWork = TRUE) { } else dependency$name target_dir <- file.path(outputDir, target_dir) + # if overwrite is false check to see if the file already exists + if(!overwrite_dir & dir_exists(target_dir)){ + dependency$src$file <- normalizePath(target_dir, "/", TRUE) + return(dependency) + } + # completely remove the target dir because we don't want possible leftover # files in the target dir, e.g. we may have lib/foo.js last time, and it was # removed from the original library, then the next time we copy the library