forked from r-lib/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-readme.R
45 lines (37 loc) · 1.21 KB
/
build-readme.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#' Build a Rmarkdown README for a package
#'
#' `build_readme()` is a wrapper around [rmarkdown::render()], it generates the
#' README.md from a README.Rmd file.
#'
#' @param path path to the package to build the readme.
#' @param ... additional arguments passed to [rmarkdown::render()]
#' @inheritParams install
#' @export
build_readme <- function(path = ".", quiet = TRUE, ...) {
check_suggested("rmarkdown")
save_all()
pkg <- as.package(path)
readme_path <- grep(
ignore.case = TRUE, value = TRUE,
"readme[.]rmd",
list.files(c(pkg$path, file.path(pkg$path, "inst"),
full.names = TRUE
))
)
if (length(readme_path) == 0) {
return(invisible())
}
readme_path <- file.path(pkg$path, readme_path[[1]])
build <- function(pkg_path, readme_path, ..., quiet) {
withr::with_temp_libpaths(action = "prefix", code = {
devtools::install(pkg_path, upgrade = "never", reload = FALSE, quiet = quiet)
rmarkdown::render(readme_path, ..., quiet = quiet)
})
}
message("Building ", pkg$package, " readme")
output <- callr::r(build,
args = list(pkg_path = pkg$path, readme_path = readme_path, ... = ..., quiet = quiet),
show = TRUE, spinner = FALSE
)
invisible(TRUE)
}