diff --git a/DESCRIPTION b/DESCRIPTION index ec70d59..697890c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: quarto Title: R Interface to 'Quarto' Markdown Publishing System -Version: 1.4.4.9011 +Version: 1.4.4.9012 Authors@R: c( person("JJ", "Allaire", , "jj@posit.co", role = "aut", comment = c(ORCID = "0000-0003-0174-9868")), diff --git a/NEWS.md b/NEWS.md index 57661bb..8fbf4c8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # quarto (development version) +- Make `quarto_render(as_job = TRUE)` wrapable (thanks, @salim-b, #105). + - Quarto CLI will now correctly use the same R version than the one used to run functions in this package (#204). - Add `quarto_available()` function to check if Quarto CLI is found (thanks, @hadley, #187). diff --git a/R/render.R b/R/render.R index 298e42e..2054afe 100644 --- a/R/render.R +++ b/R/render.R @@ -120,8 +120,18 @@ quarto_render <- function( "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( diff --git a/tests/testthat/test-render.R b/tests/testthat/test-render.R index eedc0fd..745ff81 100644 --- a/tests/testthat/test-render.R +++ b/tests/testthat/test-render.R @@ -65,3 +65,37 @@ 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 + # This is here for manual testing. This test should not run otherwise. + skip_on_cran() + skip_if_no_quarto() + skip_if_not( + rstudioapi::isAvailable() && + rstudioapi::hasFun("runScriptJob") && + in_rstudio(), + message = "quarto_render(as_job = TRUE) is only available in RStudio IDE sessions with job support." + ) + 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 + ) + } + expect_message( + wrapper(basename(qmd), output, "native"), + "Rendering project as background job" + ) + # wait for background job to finish (10s should be conservative enough) + Sys.sleep(10) + expect_true(file.exists(output)) +})