Skip to content

Commit 66c2846

Browse files
committed
Pass .libPaths() as R_LIBS to quarto subprocess
1 parent 1002b53 commit 66c2846

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Imports:
3030
rstudioapi,
3131
tools,
3232
utils,
33+
withr,
3334
xfun,
3435
yaml (>= 2.3.10)
3536
Suggests:
@@ -53,8 +54,7 @@ Suggests:
5354
thematic,
5455
tidyverse,
5556
tinytable,
56-
whoami,
57-
withr
57+
whoami
5858
VignetteBuilder:
5959
quarto
6060
Config/testthat/edition: 3

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# quarto (development version)
22

3+
- `.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 (thanks, )
4+
35
# quarto 1.5.1
46

57
- 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

R/quarto.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ quarto_run <- function(
128128
args = character(),
129129
quarto_bin = find_quarto(),
130130
echo = FALSE,
131+
libpaths = .libPaths(),
131132
echo_cmd = getOption("quarto.echo_cmd", FALSE),
132133
...,
133134
.call = rlang::caller_env()
@@ -138,6 +139,12 @@ quarto_run <- function(
138139
if (!quarto_available(min = "1.8.13")) {
139140
custom_env <- c("current", QUARTO_R = R.home("bin"))
140141
}
142+
opt_in_libpath <- getOption("quarto.use_libpaths", TRUE)
143+
if (isTRUE(opt_in_libpath) && !is.null(libpaths)) {
144+
withr::local_envvar(list(
145+
R_LIBS = paste(libpaths, collapse = .Platform$path.sep)
146+
))
147+
}
141148
res <- withCallingHandlers(
142149
processx::run(
143150
quarto_bin,

R/render.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
#' advanced usage and useful for CLI arguments which are not yet mirrored in a
5252
#' dedicated parameter of this \R function. See `quarto render --help` for options.
5353
#' @param pandoc_args Additional command line arguments to pass on to Pandoc.
54+
#' @param libpaths A character vector of library paths to use for the R session run by Quarto.
55+
#' If `NULL`, no library paths will be pass to quarto subprocess and defaults R one will be used.
56+
#' Setting `options(quarto.use_libpaths = FALSE)` will disable this behavior and
57+
#' never pass library paths to quarto subprocess.
5458
#' @param as_job Render as an RStudio background job. Default is `"auto"`,
5559
#' which will render individual documents normally and projects as
5660
#' background jobs. Use the `quarto.render_as_job` \R option to control
@@ -95,6 +99,7 @@ quarto_render <- function(
9599
profile = NULL,
96100
quarto_args = NULL,
97101
pandoc_args = NULL,
102+
libpaths = .libPaths(),
98103
as_job = getOption("quarto.render_as_job", "auto")
99104
) {
100105
# get quarto binary
@@ -222,7 +227,7 @@ quarto_render <- function(
222227
}
223228

224229
# run quarto
225-
quarto_run(args, echo = TRUE, quarto_bin = quarto_bin)
230+
quarto_run(args, echo = TRUE, quarto_bin = quarto_bin, libpaths = libpaths)
226231

227232
# no return value
228233
invisible(NULL)

man/quarto_render.Rd

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-quarto.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,26 @@ test_that("quarto_available()", {
157157
regexp = "Minimum version expected is 1.9.5"
158158
)
159159
})
160+
161+
test_that("quarto sees same libpaths as main process", {
162+
skip_if_no_quarto()
163+
skip_on_cran()
164+
qmd <- local_qmd_file(c("```{r}", "#| echo: false", ".libPaths()", "```"))
165+
tmp_lib <- withr::local_tempdir("tmp_libpath")
166+
withr::local_libpaths(tmp_lib, action = "prefix")
167+
withr::local_dir(dirname(qmd))
168+
out <- "out.md"
169+
# .libPaths() is known in Quarto render
170+
quarto_render(qmd, output_format = "gfm", output_file = out, quiet = TRUE)
171+
expect_match(readLines(out), basename(tmp_lib), all = FALSE, fixed = TRUE)
172+
# Opting-out globally
173+
withr::with_options(
174+
list(quarto.use_libpaths = FALSE),
175+
quarto_render(qmd, output_format = "gfm", output_file = out, quiet = TRUE)
176+
)
177+
expect_no_match(readLines(out), basename(tmp_lib), fixed = TRUE)
178+
# Opting-out at command
179+
quarto_render(qmd, output_format = "gfm", output_file = out, quiet = TRUE, libpaths = NULL)
180+
expect_no_match(readLines(out), basename(tmp_lib), fixed = TRUE)
181+
182+
})

0 commit comments

Comments
 (0)