diff --git a/R/render.R b/R/render.R index 8997fcb..15b58b8 100644 --- a/R/render.R +++ b/R/render.R @@ -107,8 +107,18 @@ quarto_render <- function(input = NULL, if (as_job && rstudioapi::isAvailable()) { message("Rendering project as background job (use as_job = FALSE to override)") script <- tempfile(fileext = ".R") + render_args <- as.list(sys.call()[-1L]) + render_args <- mapply( + function(arg, arg_name) paste0( + arg_name, + "="[nchar(arg_name) > 0L], + deparse1(eval(arg, envir = parent.frame(n = 3L))) + ), + render_args, + names(render_args) + ) writeLines( - c("library(quarto)", deparse(sys.call())), + paste0("quarto::quarto_render(", paste0(render_args, collapse = ", "), ")"), script ) rstudioapi::jobRunScript( @@ -120,7 +130,6 @@ quarto_render <- function(input = NULL, return(invisible(NULL)) } - # build args args <- c("render", input) if (!missing(output_format)) { diff --git a/tests/testthat/test-render.R b/tests/testthat/test-render.R index 82f0d16..21b823f 100644 --- a/tests/testthat/test-render.R +++ b/tests/testthat/test-render.R @@ -59,3 +59,28 @@ test_that("quarto_args in quarto_render", { transform = transform_quarto_cli_in_output(full_path = TRUE) ) }) + +test_that("`quarto_render(as_job = TRUE)` is wrapable", { + # this tests background jobs, a feature only available in interactive RStudio IDE sesssions + skip_on_cran() + skip_if_no_quarto() + skip_if_not(rstudioapi::isAvailable()) + qmd <- local_qmd_file(c("content")) + withr::local_dir(dirname(qmd)) + output <- basename( + withr::local_file(xfun::with_ext(qmd, ".native")) + ) + wrapper <- function(path, out, format) { + quarto_render( + input = path, + output_file = out, + output_format = format, + quiet = TRUE, + as_job = TRUE + ) + } + wrapper(basename(qmd), output, "native") + # wait for background job to finish (10s should be conservative enough) + Sys.sleep(10) + expect_true(file.exists(output)) +})