diff --git a/DESCRIPTION b/DESCRIPTION index 6833c02fc7..df1d5e3fb3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rmarkdown Type: Package Title: Dynamic Documents for R -Version: 2.11.1 +Version: 2.11.2 Authors@R: c( person("JJ", "Allaire", role = "aut", email = "jj@rstudio.com"), person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), diff --git a/NEWS.md b/NEWS.md index b2e362f81f..c3627cfb8a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ rmarkdown 2.12 ================================================================================ +- `draft()` now works with `devtools::load_all()` and **testthat** when used in other packages. rmarkdown 2.11 ================================================================================ diff --git a/R/draft.R b/R/draft.R index c18dbc19e7..afc3a62a5d 100644 --- a/R/draft.R +++ b/R/draft.R @@ -63,7 +63,7 @@ draft <- function(file, # resolve package file if (!is.null(package)) { - template_path = system.file("rmarkdown", "templates", template, + template_path = pkg_file("rmarkdown", "templates", template, package = package) if (!nzchar(template_path)) { stop("The template '", template, "' was not found in the ", diff --git a/R/util.R b/R/util.R index 5e3b958948..3a9a748ec1 100644 --- a/R/util.R +++ b/R/util.R @@ -47,11 +47,11 @@ pandoc_output_ext <- function(ext, to, input) { # From pkgdown: # https://github.com/r-lib/pkgdown/blob/04d3a76892320ac4bd918b39604c157e9f83507a/R/utils-fs.R#L85 pkg_file <- function(..., package = "rmarkdown", mustWork = FALSE) { - if (is.null(devtools_meta(package))) { - system.file(..., package = package, mustWork = mustWork) - } else { + if (devtools_loaded(package)) { # used only if package has been loaded with devtools or pkgload - file.path(getNamespaceInfo(package, "path"), "inst", ...) + file.path(find.package(package), "inst", ...) + } else { + system.file(..., package = package, mustWork = mustWork) } } @@ -566,10 +566,13 @@ stop2 = function(...) stop(..., call. = FALSE) # devtools metadata ------------------------------------------------------- -# from pkgdown +# from pkgdown & downlit # https://github.com/r-lib/pkgdown/blob/77f909b0138a1d7191ad9bb3cf95e78d8e8d93b9/R/utils.r#L52 -devtools_meta <- function(package) { - ns <- .getNamespace(package) - ns[[".__DEVTOOLS__"]] +devtools_loaded <- function(x) { + if (!x %in% loadedNamespaces()) { + return(FALSE) + } + ns <- .getNamespace(x) + !is.null(ns$.__DEVTOOLS__) }