Skip to content
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.9010
Version: 1.4.4.9011
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)

- 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).
Expand Down
51 changes: 33 additions & 18 deletions R/quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
...,
.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(
Expand All @@ -136,31 +142,40 @@
echo = echo,
error_on_status = TRUE,
echo_cmd = echo_cmd,
env = custom_env,
...
)
},
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

Check warning on line 154 in R/quarto.R

View check run for this annotation

Codecov / codecov/patch

R/quarto.R#L151-L154

Added lines #L151 - L154 were not covered by tests
)
}
} 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)
Expand Down
4 changes: 1 addition & 3 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' @importFrom rmarkdown relative_to
relative_to_wd <- function(path) {
relative_to(getwd(), path)
rmarkdown::relative_to(getwd(), path)

Check warning on line 3 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L3

Added line #L3 was not covered by tests
}

#' @importFrom yaml write_yaml
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/quarto.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-render.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
Expand Down