diff --git a/R/build-articles.R b/R/build-articles.R index 23dd8be86..da22516d2 100644 --- a/R/build-articles.R +++ b/R/build-articles.R @@ -199,7 +199,8 @@ build_article <- function(name, pkg = ".", data = list(), lazy = FALSE, - quiet = TRUE) { + quiet = TRUE, + new_process = TRUE) { pkg <- as_pkgdown(pkg) # Look up in pkg vignette data - this allows convenient automatic @@ -283,6 +284,7 @@ build_article <- function(name, output = output_file, output_format = format, output_options = options, + new_process = new_process, quiet = quiet ) } diff --git a/R/rmarkdown.R b/R/rmarkdown.R index f13241862..f404538fe 100644 --- a/R/rmarkdown.R +++ b/R/rmarkdown.R @@ -1,7 +1,7 @@ #' Render RMarkdown document in a fresh session #' #' @noRd -render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet = TRUE) { +render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, new_process = TRUE, quiet = TRUE) { input_path <- path_abs(input, pkg$src_path) output_path <- path_abs(output, pkg$dst_path) @@ -23,28 +23,35 @@ render_rmarkdown <- function(pkg, input, output, ..., copy_images = TRUE, quiet ..., quiet = quiet ) - - path <- tryCatch( - callr::r_safe( - function(...) rmarkdown::render(...), - args = args, - show = !quiet, - env = c( - callr::rcmd_safe_env(), - BSTINPUTS = bst_paths(input_path), - TEXINPUTS = tex_paths(input_path), - BIBINPUTS = bib_paths(input_path), - R_CLI_NUM_COLORS = 256 - ) - ), - error = function(cnd) { - rule("RMarkdown error") - cat(gsub("\r", "", cnd$stderr, fixed = TRUE)) - rule() - abort("Failed to render RMarkdown", parent = cnd) - } + envir <- c( + callr::rcmd_safe_env(), + BSTINPUTS = bst_paths(input_path), + TEXINPUTS = tex_paths(input_path), + BIBINPUTS = bib_paths(input_path), + R_CLI_NUM_COLORS = 256 ) + + if (new_process) { + path <- tryCatch( + callr::r_safe( + function(...) rmarkdown::render(...), + args = args, + show = !quiet, + envir = + ), + error = function(cnd) { + rule("RMarkdown error") + cat(gsub("\r", "", cnd$stderr, fixed = TRUE)) + rule() + abort("Failed to render RMarkdown", parent = cnd) + } + ) + } else { + withr::local_envvar(envir) + path <- inject(rmarkdown::render(!!!args)) + } + if (identical(path_ext(path)[[1]], "html")) { update_html( path,