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
Expand Up @@ -60,6 +60,6 @@ VignetteBuilder:
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
SystemRequirements: Quarto command line tool
(<https://github.com/quarto-dev/quarto-cli>).
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)

- `.libPaths()` from the calling R session will now be passed by default to all call to quarto as a subprocess. This should solve issue with **pkgdown** or when building vignettes.

# quarto 1.5.1

- Make sure tests pass on CRAN checks even when Quarto is not installed by adding a gihub action to test when no quarto is available. Also fix tests that were
Expand Down
2 changes: 1 addition & 1 deletion R/preview.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' @param quiet Suppress warning and other messages, from R and also Quarto CLI
#' (i.e `--quiet` is passed as command line)
#'
#' @return The URL of the preview server (invisibly). This can be used to
#' @return The URL of the preview server (invisibly). This can be used to
#' programmatically access the server location, for example to take screenshots
#' with webshot2 or pass to other automation tools.
#'
Expand Down
25 changes: 23 additions & 2 deletions R/quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,37 @@ quarto_run <- function(
args = character(),
quarto_bin = find_quarto(),
echo = FALSE,
libpaths = .libPaths(),
echo_cmd = getOption("quarto.echo_cmd", FALSE),
...,
.call = rlang::caller_env()
) {
# To store any environment variables to pass to the process
custom_env <- NULL

# 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.13")) {
custom_env <- c("current", QUARTO_R = R.home("bin"))
custom_env <- c(custom_env, QUARTO_R = R.home("bin"))
}

# handle session .libpaths() for background session
# It needs to be passed if .libPaths() was modified in the current R session
# (e.g. to install dev package in a temporary library)
opt_in_libpath <- getOption("quarto.use_libpaths", TRUE)
if (isTRUE(opt_in_libpath) && !is.null(libpaths)) {
custom_env <- c(
custom_env,
R_LIBS = paste(libpaths, collapse = .Platform$path.sep)
)
}

# This is required because `"current"` only is not supported by processx
# FIXME: https://github.com/r-lib/processx/issues/399
if (!is.null(custom_env)) {
custom_env <- c("current", custom_env)
}

res <- withCallingHandlers(
processx::run(
quarto_bin,
Expand Down
7 changes: 6 additions & 1 deletion R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
#' advanced usage and useful for CLI arguments which are not yet mirrored in a
#' dedicated parameter of this \R function. See `quarto render --help` for options.
#' @param pandoc_args Additional command line arguments to pass on to Pandoc.
#' @param libpaths A character vector of library paths to use for the R session run by Quarto.
#' If `NULL`, no library paths will be pass to quarto subprocess and defaults R one will be used.
#' Setting `options(quarto.use_libpaths = FALSE)` will disable this behavior and
#' never pass library paths to quarto subprocess.
#' @param as_job Render as an RStudio background job. Default is `"auto"`,
#' which will render individual documents normally and projects as
#' background jobs. Use the `quarto.render_as_job` \R option to control
Expand Down Expand Up @@ -95,6 +99,7 @@ quarto_render <- function(
profile = NULL,
quarto_args = NULL,
pandoc_args = NULL,
libpaths = .libPaths(),
as_job = getOption("quarto.render_as_job", "auto")
) {
# get quarto binary
Expand Down Expand Up @@ -222,7 +227,7 @@ quarto_render <- function(
}

# run quarto
quarto_run(args, echo = TRUE, quarto_bin = quarto_bin)
quarto_run(args, echo = TRUE, quarto_bin = quarto_bin, libpaths = libpaths)

# no return value
invisible(NULL)
Expand Down
2 changes: 1 addition & 1 deletion man/check_newer_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/find_project_root.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/quarto_render.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/resources/purl-r-ojs.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#' title: Purl Test Document
#' format: html
#' ---
#'
#'

2 changes: 2 additions & 0 deletions tests/testthat/test-quarto-args.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test_that("create quiete arg", {
})

test_that("quarto.quiet options takes over", {
withr::local_envvar(list(R_QUARTO_QUIET = NA))
expect_identical(is_quiet(TRUE), TRUE)
expect_identical(is_quiet(FALSE), FALSE)
expect_identical(is_quiet(NA), FALSE)
Expand Down Expand Up @@ -63,6 +64,7 @@ test_that("R_QUARTO_QUIET options takes over", {
})

test_that("quarto.quiet options takes over R_QUARTO_QUIET", {
withr::local_envvar(list(R_QUARTO_QUIET = NA))
withr::with_options(list(quarto.quiet = TRUE), {
withr::with_envvar(list(R_QUARTO_QUIET = FALSE), {
expect_identical(is_quiet(TRUE), TRUE)
Expand Down
25 changes: 25 additions & 0 deletions tests/testthat/test-quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,28 @@ test_that("quarto_available()", {
regexp = "Minimum version expected is 1.9.5"
)
})

test_that("quarto sees same libpaths as main process", {
skip_if_no_quarto()
skip_on_cran()
# Issue on windows with libpaths
# https://github.com/quarto-dev/quarto-r/issues/217
skip_on_os("windows")
qmd <- local_qmd_file(c("```{r}", "#| echo: false", ".libPaths()", "```"))
tmp_lib <- withr::local_tempdir("tmp_libpath")
withr::local_libpaths(tmp_lib, action = "prefix")
withr::local_dir(dirname(qmd))
out <- "out.md"
# .libPaths() is known in Quarto render
out <- .render_and_read(qmd, output_format = "gfm")
expect_match(out, basename(tmp_lib), all = FALSE, fixed = TRUE)
# Opting-out globally
withr::with_options(
list(quarto.use_libpaths = FALSE),
out <- .render_and_read(qmd, output_format = "gfm")
)
expect_no_match(out, basename(tmp_lib), fixed = TRUE)
# Opting-out at command
out <- .render_and_read(qmd, output_format = "gfm", libpaths = NULL)
expect_no_match(out, basename(tmp_lib), fixed = TRUE)
})
1 change: 1 addition & 0 deletions tests/testthat/test-render.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ test_that("metadata-file and metadata are merged in quarto_render", {

test_that("quarto_args in quarto_render", {
skip_if_no_quarto()
withr::local_envvar(list(QUARTO_R_QUIET = NA))
qmd <- local_qmd_file(c("content"))
local_quarto_run_echo_cmd()
withr::local_dir(dirname(qmd))
Expand Down
Loading