Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion R/html_dependency.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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)){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition dir_exists(target_dir) may be a little weak. A stronger version is to check if all filenames in the target dir and the dependency object are identical. This makes sure when the dependency is updated (in future versions of the package where the dependency is introduced), you'll get the new version.

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
Expand Down