Skip to content

Commit

Permalink
Add ability to keep markdown files when building vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
jimhester authored and HughParsonage committed Jul 2, 2019
1 parent 1ac8ede commit 8d6a524
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# devtools 1.13.3.9000

* `build_vignette()` gains a `keep_md` option to allow keeping the intermediate markdown output (#1726)

* Bioconductor support now provided by the BiocManager CRAN package instead of
BiocInstaller (#1833).

Expand Down
9 changes: 7 additions & 2 deletions R/vignette-r.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# A copy of the GNU General Public License is available at
# http://www.r-project.org/Licenses/

copy_vignettes <- function(pkg) {
copy_vignettes <- function(pkg, keep_md) {
pkg <- as.package(pkg)

usethis_use_directory(pkg, "doc", ignore = TRUE)
Expand All @@ -27,7 +27,12 @@ copy_vignettes <- function(pkg) {
vigns <- tools::pkgVignettes(dir = pkg$path, output = TRUE, source = TRUE)
if (length(vigns$docs) == 0) return(invisible())

out_mv <- c(vigns$outputs, unique(unlist(vigns$sources, use.names = FALSE)))
md_outputs <- character()
if (isTRUE(keep_md)) {
md_outputs <- list.files(path = vigns$dir, pattern = "[.]md$", full.names = TRUE)
}

out_mv <- c(md_outputs, vigns$outputs, unique(unlist(vigns$sources, use.names = FALSE)))
out_cp <- vigns$docs

message("Moving ", paste(basename(out_mv), collapse = ", "), " to doc/")
Expand Down
13 changes: 9 additions & 4 deletions R/vignettes.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#' if you need to debug.
#' @param install If \code{TRUE}, install the package before building
#' vignettes.
#' @param keep_md If \code{TRUE}, move md intermediates as well as rendered
#' outputs. Most useful when using the `keep_md` YAML option for Rmarkdown
#' outputs. See
#' \link{https://bookdown.org/yihui/rmarkdown/html-document.html#keeping-markdown}.
#' @inheritParams tools::buildVignettes
#' @inheritParams install_deps
#' @keywords programming
Expand All @@ -26,9 +30,10 @@
build_vignettes <- function(pkg = ".",
dependencies = "VignetteBuilder",
clean = TRUE,
upgrade = FALSE,
upgrade = TRUE,
quiet = TRUE,
install = TRUE
install = TRUE,
keep_md = TRUE
) {
pkg <- as.package(pkg)
vigns <- tools::pkgVignettes(dir = pkg$path)
Expand All @@ -41,7 +46,7 @@ build_vignettes <- function(pkg = ".",
if (isTRUE(install)) {
build <- function(pkg_path, clean, quiet) {
withr::with_temp_libpaths(action = "prefix", {
devtools::install(pkg_path, upgrade_dependencies = FALSE, reload = FALSE, quiet = quiet)
devtools::install(pkg_path, upgrade_dependencies = upgrade, reload = FALSE, quiet = quiet)
tools::buildVignettes(dir = pkg_path, clean = clean, tangle = TRUE, quiet = quiet)
})
}
Expand All @@ -61,7 +66,7 @@ build_vignettes <- function(pkg = ".",
# files as well
vigns <- tools::pkgVignettes(dir = pkg$path, source = TRUE, output = TRUE)

copy_vignettes(pkg)
copy_vignettes(pkg, keep_md)

create_vignette_index(pkg, vigns)

Expand Down
7 changes: 6 additions & 1 deletion man/build_vignettes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion vignettes/dependencies.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
title: "Devtools dependencies"
author: "Jim Hester, Hadley Wickham"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
output:
rmarkdown::html_vignette:
keep_md: true
vignette: >
%\VignetteIndexEntry{Devtools dependencies}
%\VignetteEngine{knitr::rmarkdown}
Expand Down

0 comments on commit 8d6a524

Please sign in to comment.