From 9bc8e29560caa3e98b2fac8b4a8bb8bd81d802cb Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Jun 2025 12:13:20 +0200 Subject: [PATCH 1/6] move import where it is used --- R/render.R | 4 +--- R/utils.R | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/R/render.R b/R/render.R index 7b9bd653..2cb0c8cb 100644 --- a/R/render.R +++ b/R/render.R @@ -43,7 +43,7 @@ #' `quarto.quiet` \R option or `QUARTO_R_QUIET` environment variable can be used to globally override a function call #' (This can be useful to debug tool that calls `quarto_*` functions directly). #' -#' On Github Actions, it will always be `quiet=FALSE`. +#' On Github Actions, it will always be `quiet = FALSE`. #' @param profile [Quarto project #' profile(s)](https://quarto.org/docs/projects/profiles.html) to use. Either #' a character vector of profile names or `NULL` to use the default profile. @@ -57,8 +57,6 @@ #' background jobs. Use the `quarto.render_as_job` \R option to control #' the default globally. #' -#' @importFrom rmarkdown relative_to -#' #' @examples #' \dontrun{ #' # Render R Markdown diff --git a/R/utils.R b/R/utils.R index e407013c..476048e8 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,5 +1,6 @@ +#' @importFrom rmarkdown relative_to relative_to_wd <- function(path) { - relative_to(getwd(), path) + rmarkdown::relative_to(getwd(), path) } #' @importFrom yaml write_yaml From 58094a0ea15efe80e9a40d87c3ef4660120f0374 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Jun 2025 14:33:46 +0200 Subject: [PATCH 2/6] processx can return different error than the one from `error_on_status` --- R/quarto.R | 44 +++++++++++++++++++-------------- tests/testthat/_snaps/quarto.md | 6 ++--- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/R/quarto.R b/R/quarto.R index 9b0e44fc..9d2cc569 100644 --- a/R/quarto.R +++ b/R/quarto.R @@ -140,27 +140,35 @@ quarto_run <- function( ) }, error = function(e) { - msg <- c(x = "Error running quarto cli.") - # if there is an error message from quarto CLI, add it to the message - if (e$stderr != "") { - quarto_error_msg <- xfun::split_lines(e$stderr) - names(quarto_error_msg) <- rep(" ", length(quarto_error_msg)) - msg <- c( - msg, - " " = paste0(rep("-", nchar(msg)), collapse = ""), - quarto_error_msg + if (!inherits(e, "system_command_status_error")) { + cli::cli_abort( + c("!" = "Error running quarto CLI from R."), + call = .call, + parent = e ) - } + } else { + msg <- c(x = "Error returned by quarto CLI.") + # if there is an error message from quarto CLI, add it to the message + if (e$stderr != "") { + quarto_error_msg <- xfun::split_lines(e$stderr) + names(quarto_error_msg) <- rep(" ", length(quarto_error_msg)) + msg <- c( + msg, + " " = paste0(rep("-", nchar(msg)), collapse = ""), + quarto_error_msg + ) + } - # if `--quiet` has been set, quarto CLI won't report any error (e$stderr will be empty) - # So remind user to run without `--quiet` to see the full error message - if (cli_arg_quiet() %in% args) - msg <- c( - msg, - "i" = "Rerun with `quiet = FALSE` to see the full error message." - ) + # if `--quiet` has been set, quarto CLI won't report any error (e$stderr will be empty) + # So remind user to run without `--quiet` to see the full error message + if (cli_arg_quiet() %in% args) + msg <- c( + msg, + "i" = "Rerun with `quiet = FALSE` to see the full error message." + ) - cli::cli_abort(msg, call = .call, parent = e) + cli::cli_abort(msg, call = .call, parent = e) + } } ) invisible(res) diff --git a/tests/testthat/_snaps/quarto.md b/tests/testthat/_snaps/quarto.md index 93f6a882..1f0b045e 100644 --- a/tests/testthat/_snaps/quarto.md +++ b/tests/testthat/_snaps/quarto.md @@ -4,7 +4,7 @@ quarto_run(c("rend", "--quiet")) Condition Error: - x Error running quarto cli. + x Error returned by quarto CLI. i Rerun with `quiet = FALSE` to see the full error message. Caused by error: ! System command 'quarto' failed @@ -15,8 +15,8 @@ quarto_inspect() Condition Error in `quarto_inspect()`: - x Error running quarto cli. - ------------------------- + x Error returned by quarto CLI. + ----------------------------- ERROR: Book chapter 'intro.qmd' not found Stack trace: From 4e67f0adb7808e60e2a5e4071b8a1fe06b101e1a Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Jun 2025 15:02:16 +0200 Subject: [PATCH 3/6] Set `QUARTO_R` for ealier versions of Quarto to overcome the R_HOME detection problem Fixed in 1.8 at https://github.com/quarto-dev/quarto-cli/pull/12887 --- R/quarto.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/quarto.R b/R/quarto.R index 9d2cc569..83126820 100644 --- a/R/quarto.R +++ b/R/quarto.R @@ -128,6 +128,12 @@ quarto_run <- function( ..., .call = rlang::caller_env() ) { + # This is required due to a bug in QUARTO CLI, fixed only in 1.8+ + # https://github.com/quarto-dev/quarto-cli/pull/12887 + custom_env <- NULL + if (!quarto_available(min = "1.8.12")) { + custom_env <- c("current", QUARTO_R = R.home("bin")) + } res <- tryCatch( { processx::run( @@ -136,6 +142,7 @@ quarto_run <- function( echo = echo, error_on_status = TRUE, echo_cmd = echo_cmd, + env = custom_env, ... ) }, From f61749037a6d2bf30bd00dbded8c80d8f224f6ef Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Jun 2025 15:02:28 +0200 Subject: [PATCH 4/6] missing test_path in tests --- tests/testthat/test-render.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-render.R b/tests/testthat/test-render.R index ae8a1d48..eedc0fdf 100644 --- a/tests/testthat/test-render.R +++ b/tests/testthat/test-render.R @@ -6,7 +6,7 @@ test_that("An error is reported when Quarto is not installed", { test_that("R Markdown documents can be rendered", { skip_if_no_quarto() - quarto_render("test.Rmd", quiet = TRUE) + quarto_render(test_path("test.Rmd"), quiet = TRUE) expect_true(file.exists("test.html")) unlink("test.html") }) From 83a38a30ac390f1af1dc8ceee95cecf4a3e0cf10 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Jun 2025 15:05:17 +0200 Subject: [PATCH 5/6] Add NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 7ff552d2..57661bb4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # quarto (development version) +- 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). - `quarto_render()` now correctly set `as_job` when not inside RStudio IDE and required **rstudioapi** functions are not available (#203). From 67e2b50b0fe8ed0015dfa7b4214719b25cf07e50 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Jun 2025 15:05:36 +0200 Subject: [PATCH 6/6] bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 40fd6023..ec70d591 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: quarto Title: R Interface to 'Quarto' Markdown Publishing System -Version: 1.4.4.9010 +Version: 1.4.4.9011 Authors@R: c( person("JJ", "Allaire", , "jj@posit.co", role = "aut", comment = c(ORCID = "0000-0003-0174-9868")),