Skip to content

Commit 975ca64

Browse files
authored
Merge branch 'main' into main
2 parents dde5346 + 8a0d1ee commit 975ca64

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
- Added a `new_blog_post()` function (thanks, @topeto, #22).
44

5+
- Make `quarto_render(as_job = TRUE)` wrapable (thanks, @salim-b, #105).
6+
57
- Quarto CLI will now correctly use the same R version than the one used to run functions in this package (#204).
68

79
- Add `quarto_available()` function to check if Quarto CLI is found (thanks, @hadley, #187).

R/render.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,18 @@ quarto_render <- function(
120120
"Rendering project as background job (use as_job = FALSE to override)"
121121
)
122122
script <- tempfile(fileext = ".R")
123+
render_args <- as.list(sys.call()[-1L])
124+
render_args <- mapply(
125+
function(arg, arg_name) paste0(
126+
arg_name,
127+
"="[nchar(arg_name) > 0L],
128+
deparse1(eval(arg, envir = parent.frame(n = 3L)))
129+
),
130+
render_args,
131+
names(render_args)
132+
)
123133
writeLines(
124-
c("library(quarto)", deparse(sys.call())),
134+
paste0("quarto::quarto_render(", paste0(render_args, collapse = ", "), ")"),
125135
script
126136
)
127137
rstudioapi::jobRunScript(

tests/testthat/test-render.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,37 @@ test_that("quarto_args in quarto_render", {
6565
transform = transform_quarto_cli_in_output(full_path = TRUE)
6666
)
6767
})
68+
69+
test_that("`quarto_render(as_job = TRUE)` is wrapable", {
70+
# this tests background jobs, a feature only available in interactive RStudio IDE sesssions
71+
# This is here for manual testing. This test should not run otherwise.
72+
skip_on_cran()
73+
skip_if_no_quarto()
74+
skip_if_not(
75+
rstudioapi::isAvailable() &&
76+
rstudioapi::hasFun("runScriptJob") &&
77+
in_rstudio(),
78+
message = "quarto_render(as_job = TRUE) is only available in RStudio IDE sessions with job support."
79+
)
80+
qmd <- local_qmd_file(c("content"))
81+
withr::local_dir(dirname(qmd))
82+
output <- basename(
83+
withr::local_file(xfun::with_ext(qmd, ".native"))
84+
)
85+
wrapper <- function(path, out, format) {
86+
quarto_render(
87+
input = path,
88+
output_file = out,
89+
output_format = format,
90+
quiet = TRUE,
91+
as_job = TRUE
92+
)
93+
}
94+
expect_message(
95+
wrapper(basename(qmd), output, "native"),
96+
"Rendering project as background job"
97+
)
98+
# wait for background job to finish (10s should be conservative enough)
99+
Sys.sleep(10)
100+
expect_true(file.exists(output))
101+
})

0 commit comments

Comments
 (0)