Skip to content

Commit

Permalink
Add support for devtools loaded package in draft() (#2224)
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv authored Sep 23, 2021
1 parent 2cb1b7e commit 71ae829
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rmarkdown 2.12
================================================================================

- `draft()` now works with `devtools::load_all()` and **testthat** when used in other packages.

rmarkdown 2.11
================================================================================
Expand Down
2 changes: 1 addition & 1 deletion R/draft.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ",
Expand Down
19 changes: 11 additions & 8 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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__)
}

0 comments on commit 71ae829

Please sign in to comment.