diff --git a/DESCRIPTION b/DESCRIPTION index d560673..2c8ada4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 (). diff --git a/NEWS.md b/NEWS.md index 7742812..b6afd5b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/preview.R b/R/preview.R index 203f01b..c36cc9f 100644 --- a/R/preview.R +++ b/R/preview.R @@ -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. #' diff --git a/R/quarto.R b/R/quarto.R index c0e7b8f..c1ca568 100644 --- a/R/quarto.R +++ b/R/quarto.R @@ -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, diff --git a/R/render.R b/R/render.R index 006b5bf..8c17e6b 100644 --- a/R/render.R +++ b/R/render.R @@ -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 @@ -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 @@ -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) diff --git a/man/check_newer_version.Rd b/man/check_newer_version.Rd index de69a22..42ea436 100644 --- a/man/check_newer_version.Rd +++ b/man/check_newer_version.Rd @@ -47,7 +47,7 @@ information from quarto.org. If the network request fails, an error will be thro } \examples{ -\dontshow{if (quarto::quarto_available() && quarto:::has_internet("https://www.quarto.org")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (quarto::quarto_available() && quarto:::has_internet("https://www.quarto.org")) withAutoprint(\{ # examplesIf} # Check current Quarto version check_newer_version() diff --git a/man/find_project_root.Rd b/man/find_project_root.Rd index d5df6e1..a7e9576 100644 --- a/man/find_project_root.Rd +++ b/man/find_project_root.Rd @@ -20,7 +20,7 @@ Unlike \code{\link[=get_running_project_root]{get_running_project_root()}}, this interactive sessions. } \examples{ -\dontshow{if (quarto_available()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (quarto_available()) withAutoprint(\{ # examplesIf} tmpdir <- tempfile() dir.create(tmpdir) find_project_root(tmpdir) diff --git a/man/quarto_render.Rd b/man/quarto_render.Rd index 7b2e768..c728ee9 100644 --- a/man/quarto_render.Rd +++ b/man/quarto_render.Rd @@ -24,6 +24,7 @@ quarto_render( profile = NULL, quarto_args = NULL, pandoc_args = NULL, + libpaths = .libPaths(), as_job = getOption("quarto.render_as_job", "auto") ) } @@ -93,6 +94,11 @@ dedicated parameter of this \R function. See \verb{quarto render --help} for opt \item{pandoc_args}{Additional command line arguments to pass on to Pandoc.} +\item{libpaths}{A character vector of library paths to use for the R session run by Quarto. +If \code{NULL}, no library paths will be pass to quarto subprocess and defaults R one will be used. +Setting \code{options(quarto.use_libpaths = FALSE)} will disable this behavior and +never pass library paths to quarto subprocess.} + \item{as_job}{Render as an RStudio background job. Default is \code{"auto"}, which will render individual documents normally and projects as background jobs. Use the \code{quarto.render_as_job} \R option to control diff --git a/tests/testthat/resources/purl-r-ojs.R b/tests/testthat/resources/purl-r-ojs.R index 7374287..eb732e6 100644 --- a/tests/testthat/resources/purl-r-ojs.R +++ b/tests/testthat/resources/purl-r-ojs.R @@ -2,5 +2,5 @@ #' title: Purl Test Document #' format: html #' --- -#' +#' diff --git a/tests/testthat/test-quarto-args.R b/tests/testthat/test-quarto-args.R index 2ce099c..bc1f3d6 100644 --- a/tests/testthat/test-quarto-args.R +++ b/tests/testthat/test-quarto-args.R @@ -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) @@ -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) diff --git a/tests/testthat/test-quarto.R b/tests/testthat/test-quarto.R index e4d7aab..9111563 100644 --- a/tests/testthat/test-quarto.R +++ b/tests/testthat/test-quarto.R @@ -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) +}) diff --git a/tests/testthat/test-render.R b/tests/testthat/test-render.R index dee7a2e..b6e2574 100644 --- a/tests/testthat/test-render.R +++ b/tests/testthat/test-render.R @@ -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))