From b30f2d41214f6cebecabc47621c8ce1cd5b01de9 Mon Sep 17 00:00:00 2001 From: christophe dervieux Date: Thu, 23 Sep 2021 13:52:24 +0200 Subject: [PATCH 1/3] Add support for devtools loaded package in `draft()` --- R/draft.R | 2 +- R/util.R | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) 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__) } From 547de78b0b258feba8db98128c50f60c839e87b1 Mon Sep 17 00:00:00 2001 From: christophe dervieux Date: Thu, 23 Sep 2021 13:56:24 +0200 Subject: [PATCH 2/3] Add NEWS [skip ci] --- NEWS.md | 1 + 1 file changed, 1 insertion(+) 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 ================================================================================ From 530c77823141035191fad91810885036ac766ae0 Mon Sep 17 00:00:00 2001 From: christophe dervieux Date: Thu, 23 Sep 2021 15:01:28 +0200 Subject: [PATCH 3/3] bump version [skip ci] --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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")),