Skip to content

Commit 8a0d1ee

Browse files
salim-bcderv
andauthored
Make quarto_render(as_job = TRUE) wrapable (#105)
* Make `quarto_render()` wrapable * Cosmetic fixes * Avoid rlang * Fix test * Fix order in test * Tweak test * Cosmetic fix * Use temp file infrastructure for tests * Tweak test * correctly skip test fixup correct function name * Add note to test * add test for message checking we are in job part * bump version --------- Co-authored-by: Christophe Dervieux <[email protected]>
1 parent 95a54a1 commit 8a0d1ee

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: quarto
22
Title: R Interface to 'Quarto' Markdown Publishing System
3-
Version: 1.4.4.9011
3+
Version: 1.4.4.9012
44
Authors@R: c(
55
person("JJ", "Allaire", , "[email protected]", role = "aut",
66
comment = c(ORCID = "0000-0003-0174-9868")),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# quarto (development version)
22

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

57
- 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)