Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for devtools loaded package in draft() #2224

Merged
merged 3 commits into from
Sep 23, 2021
Merged
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
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__)
}