From c4c3f5c7f01c5c985fdfb512230a82cc5f5738ac Mon Sep 17 00:00:00 2001 From: Ryan Haunfelder Date: Tue, 18 Sep 2018 22:37:19 -0600 Subject: [PATCH 1/3] Adds the parameter overwrite_dir to the copyDependenciesToDir function which allows the user to specify whether or not html dependencies should be overwritten. When used to, for example, render rmarkdown html documents this can speed up I/O time considerably. If the dependency does not exist in the target directory and overwrite_dir is FALSE, the parameter is ignored and the directory is overwritten as usual. --- R/html_dependency.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/html_dependency.R b/R/html_dependency.R index 9db94058..c9fca6ae 100644 --- a/R/html_dependency.R +++ b/R/html_dependency.R @@ -263,7 +263,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 +290,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 From f4379f57e7663699526148e4e5a80c906d447861 Mon Sep 17 00:00:00 2001 From: Ryan Haunfelder Date: Tue, 18 Sep 2018 22:52:10 -0600 Subject: [PATCH 2/3] Documents overwrite_dir parameter and adds news entry --- NEWS | 3 +++ R/html_dependency.R | 1 + 2 files changed, 4 insertions(+) diff --git a/NEWS b/NEWS index 2b3bff09..a7cd8031 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 depedencies 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 c9fca6ae..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. From b5b7cacfbb01748097a98baa1d2e8cdf4c86b451 Mon Sep 17 00:00:00 2001 From: Ryan Haunfelder Date: Tue, 18 Sep 2018 22:58:02 -0600 Subject: [PATCH 3/3] Fix typo in news --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index a7cd8031..6f633e6c 100644 --- a/NEWS +++ b/NEWS @@ -18,7 +18,7 @@ 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 depedencies in the function copyDependenciesToDir. Intended to be used with +* Adds the ability to skip overwriting existing html dependencies in the function copyDependenciesToDir. Intended to be used with rmarkdown::render to speed up rendering.