-
Notifications
You must be signed in to change notification settings - Fork 762
Deprecate build_rmd() #2675
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
Deprecate build_rmd() #2675
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,46 @@ | ||
| #' Build a Rmarkdown files package | ||
| #' Build Rmarkdown files | ||
| #' | ||
| #' `build_rmd()` is a wrapper around [rmarkdown::render()] that first installs | ||
| #' a temporary copy of the package, and then renders each `.Rmd` in a clean R | ||
| #' session. `build_readme()` locates your `README.Rmd` and builds it into a | ||
| #' `README.md` | ||
| #' @description | ||
| #' `r lifecycle::badge("deprecated")` | ||
| #' | ||
| #' `build_rmd()` is deprecated, as it is a low-level helper for internal use. To | ||
| #' render your package's `README.Rmd` or `README.qmd`, use [build_readme()]. To | ||
| #' preview a vignette or article, use functions like [pkgdown::build_site()] or | ||
| #' [pkgdown::build_article()]. | ||
| #' | ||
| #' @param files The Rmarkdown files to be rendered. | ||
| #' @param path path to the package to build the readme. | ||
| #' @param ... additional arguments passed to [rmarkdown::render()] | ||
| #' @inheritParams install | ||
| #' @inheritParams rmarkdown::render | ||
| #' @export | ||
| #' @keywords internal | ||
| build_rmd <- function( | ||
| files, | ||
| path = ".", | ||
| output_options = list(), | ||
| ..., | ||
| quiet = TRUE | ||
| ) { | ||
| lifecycle::deprecate_soft("2.5.0", "build_rmd()", "build_readme()") | ||
| build_rmd_impl( | ||
| files = files, | ||
| path = path, | ||
| output_options = output_options, | ||
| ..., | ||
| quiet = quiet | ||
| ) | ||
| } | ||
|
|
||
| # Created as part of the deprecation process to de-export build_rmd(). | ||
| # We still want to use this internally without needing to suppress deprecation | ||
| # signals. | ||
| build_rmd_impl <- function( | ||
| files, | ||
| path = ".", | ||
| output_options = list(), | ||
| ..., | ||
| quiet = TRUE | ||
| ) { | ||
| check_dots_used(action = getOption("devtools.ellipsis_action", warn)) | ||
|
|
||
|
|
@@ -40,7 +64,9 @@ build_rmd <- function( | |
| output_options$html_preview <- FALSE | ||
|
|
||
| for (path in paths) { | ||
| cli::cli_inform(c(i = "Building {.path {path}}")) | ||
| if (!quiet) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR but discovered while tinkering with tests. |
||
| cli::cli_inform(c(i = "Building {.path {path}}")) | ||
| } | ||
| callr::r_safe( | ||
| function(...) rmarkdown::render(...), | ||
| args = list( | ||
|
|
@@ -58,7 +84,17 @@ build_rmd <- function( | |
| invisible(TRUE) | ||
| } | ||
|
|
||
| #' @rdname build_rmd | ||
| #' Build README | ||
| #' | ||
| #' Renders an executable README, such as `README.Rmd`, to `README.md`. | ||
| #' Specifically, `build_readme()`: | ||
| #' * Installs a copy of the package's current source to a temporary library | ||
| #' * Renders the README in a clean R session | ||
| #' | ||
| #' @param path Path to the package to build the README. | ||
| #' @param quiet If `TRUE`, suppresses most output. Set to `FALSE` | ||
| #' if you need to debug. | ||
| #' @param ... Additional arguments passed to [rmarkdown::render()]. | ||
| #' @export | ||
| build_readme <- function(path = ".", quiet = TRUE, ...) { | ||
| pkg <- as.package(path) | ||
|
|
@@ -81,5 +117,5 @@ build_readme <- function(path = ".", quiet = TRUE, ...) { | |
| ) | ||
| } | ||
|
|
||
| build_rmd(readme_path, path = path, quiet = quiet, ...) | ||
| build_rmd_impl(readme_path, path = path, quiet = quiet, ...) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -236,7 +236,11 @@ install_dev_deps <- function( | |
| local_install <- function(pkg = ".", quiet = TRUE, env = parent.frame()) { | ||
| pkg <- as.package(pkg) | ||
|
|
||
| cli::cli_inform(c(i = "Installing {.pkg {pkg$package}} in temporary library")) | ||
| if (!quiet) { | ||
| cli::cli_inform(c( | ||
| i = "Installing {.pkg {pkg$package}} in temporary library" | ||
| )) | ||
| } | ||
|
Comment on lines
+239
to
+243
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR but discovered while tinkering with tests. |
||
| withr::local_temp_libpaths(.local_envir = env) | ||
| install(pkg, upgrade = FALSE, reload = FALSE, quick = TRUE, quiet = quiet) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,14 @@ test_that("can build README in root directory", { | |
| skip_on_cran() | ||
|
|
||
| pkg <- local_package_create() | ||
| suppressMessages(usethis::with_project(pkg, use_readme_rmd())) | ||
| usethis::ui_silence( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated upkeep: just using a more specific mechanism for silencing in this file. |
||
| usethis::with_project( | ||
| pkg, | ||
| use_readme_rmd(open = FALSE) | ||
| ) | ||
| ) | ||
|
|
||
| suppressMessages(build_readme(pkg)) | ||
| build_readme(pkg, quiet = TRUE) | ||
| expect_true(file_exists(path(pkg, "README.md"))) | ||
| expect_false(file_exists(path(pkg, "README.html"))) | ||
| }) | ||
|
|
@@ -13,14 +18,19 @@ test_that("can build README in inst/", { | |
| skip_on_cran() | ||
|
|
||
| pkg <- local_package_create() | ||
| suppressMessages(usethis::with_project(pkg, use_readme_rmd())) | ||
| usethis::ui_silence( | ||
| usethis::with_project( | ||
| pkg, | ||
| use_readme_rmd(open = FALSE) | ||
| ) | ||
| ) | ||
| dir_create(pkg, "inst") | ||
| file_move( | ||
| path(pkg, "README.Rmd"), | ||
| path(pkg, "inst", "README.Rmd") | ||
| ) | ||
|
|
||
| suppressMessages(build_readme(pkg)) | ||
| build_readme(pkg, quiet = TRUE) | ||
| expect_true(file_exists(path(pkg, "inst", "README.md"))) | ||
| expect_false(file_exists(path(pkg, "README.Rmd"))) | ||
| expect_false(file_exists(path(pkg, "README.md"))) | ||
|
|
@@ -31,7 +41,12 @@ test_that("useful errors if too few or too many", { | |
| pkg <- local_package_create() | ||
| expect_snapshot(build_readme(pkg), error = TRUE) | ||
|
|
||
| suppressMessages(usethis::with_project(pkg, use_readme_rmd())) | ||
| usethis::ui_silence( | ||
| usethis::with_project( | ||
| pkg, | ||
| use_readme_rmd(open = FALSE) | ||
| ) | ||
| ) | ||
| dir_create(pkg, "inst") | ||
| file_copy(path(pkg, "README.Rmd"), path(pkg, "inst", "README.Rmd")) | ||
| expect_snapshot(build_readme(pkg), error = TRUE) | ||
|
|
@@ -41,9 +56,35 @@ test_that("don't error for README in another directory", { | |
| skip_on_cran() | ||
|
|
||
| pkg <- local_package_create() | ||
| suppressMessages(usethis::with_project(pkg, use_readme_rmd(open = FALSE))) | ||
| usethis::ui_silence( | ||
| usethis::with_project( | ||
| pkg, | ||
| use_readme_rmd(open = FALSE) | ||
| ) | ||
| ) | ||
| dir_create(pkg, "data-raw") | ||
| file_create(pkg, "data-raw", "README.md") | ||
|
|
||
| expect_no_error(suppressMessages(build_readme(pkg))) | ||
| expect_no_error(build_readme(pkg, quiet = TRUE)) | ||
| }) | ||
|
|
||
| test_that("build_rmd() is deprecated", { | ||
| skip_on_cran() | ||
|
|
||
| pkg <- local_package_create() | ||
| usethis::ui_silence( | ||
| usethis::with_project( | ||
| pkg, | ||
| use_readme_rmd(open = FALSE) | ||
| ) | ||
| ) | ||
|
|
||
| withr::local_options(lifecycle_verbosity = "warning") | ||
| # it's hard (impossible?) to silence pak (cli, really) so that's what the | ||
| # suppressMessages() is for | ||
| expect_snapshot(suppressMessages(build_rmd( | ||
| "README.Rmd", | ||
| path = pkg, | ||
| quiet = TRUE | ||
| ))) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤪 this never made sense