Skip to content

Make quarto_render(as_job = TRUE) wrapable #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0003-0174-9868")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
12 changes: 11 additions & 1 deletion R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,18 @@
"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)
)

Check warning on line 132 in R/render.R

View check run for this annotation

Codecov / codecov/patch

R/render.R#L123-L132

Added lines #L123 - L132 were not covered by tests
Comment on lines +123 to +132
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to handle this a bit differently for complex wrapping calls that would use ... for example. In this case, it will not work. rlang maybe be useful for this. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, I didn't test with a wrapper function that uses dots, I only tested simple named args. Feel free to refactor and expand on this PR as you see fit!

writeLines(
c("library(quarto)", deparse(sys.call())),
paste0("quarto::quarto_render(", paste0(render_args, collapse = ", "), ")"),

Check warning on line 134 in R/render.R

View check run for this annotation

Codecov / codecov/patch

R/render.R#L134

Added line #L134 was not covered by tests
script
)
rstudioapi::jobRunScript(
Expand Down
34 changes: 34 additions & 0 deletions tests/testthat/test-render.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})