Skip to content

Commit cf080af

Browse files
authored
Pass .libPaths() as R_LIBS to quarto subprocess (#228)
1 parent d50ba11 commit cf080af

File tree

12 files changed

+70
-8
lines changed

12 files changed

+70
-8
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ VignetteBuilder:
6060
Config/testthat/edition: 3
6161
Encoding: UTF-8
6262
Roxygen: list(markdown = TRUE)
63-
RoxygenNote: 7.3.2
63+
RoxygenNote: 7.3.3
6464
SystemRequirements: Quarto command line tool
6565
(<https://github.com/quarto-dev/quarto-cli>).

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.
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/preview.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#' @param quiet Suppress warning and other messages, from R and also Quarto CLI
2525
#' (i.e `--quiet` is passed as command line)
2626
#'
27-
#' @return The URL of the preview server (invisibly). This can be used to
27+
#' @return The URL of the preview server (invisibly). This can be used to
2828
#' programmatically access the server location, for example to take screenshots
2929
#' with webshot2 or pass to other automation tools.
3030
#'

R/quarto.R

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,37 @@ 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()
134135
) {
136+
# To store any environment variables to pass to the process
137+
custom_env <- NULL
138+
135139
# This is required due to a bug in QUARTO CLI, fixed only in 1.8+
136140
# https://github.com/quarto-dev/quarto-cli/pull/12887
137-
custom_env <- NULL
138141
if (!quarto_available(min = "1.8.13")) {
139-
custom_env <- c("current", QUARTO_R = R.home("bin"))
142+
custom_env <- c(custom_env, QUARTO_R = R.home("bin"))
143+
}
144+
145+
# handle session .libpaths() for background session
146+
# It needs to be passed if .libPaths() was modified in the current R session
147+
# (e.g. to install dev package in a temporary library)
148+
opt_in_libpath <- getOption("quarto.use_libpaths", TRUE)
149+
if (isTRUE(opt_in_libpath) && !is.null(libpaths)) {
150+
custom_env <- c(
151+
custom_env,
152+
R_LIBS = paste(libpaths, collapse = .Platform$path.sep)
153+
)
140154
}
155+
156+
# This is required because `"current"` only is not supported by processx
157+
# FIXME: https://github.com/r-lib/processx/issues/399
158+
if (!is.null(custom_env)) {
159+
custom_env <- c("current", custom_env)
160+
}
161+
141162
res <- withCallingHandlers(
142163
processx::run(
143164
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/check_newer_version.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/find_project_root.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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/resources/purl-r-ojs.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
#' title: Purl Test Document
33
#' format: html
44
#' ---
5-
#'
5+
#'
66

tests/testthat/test-quarto-args.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test_that("create quiete arg", {
2424
})
2525

2626
test_that("quarto.quiet options takes over", {
27+
withr::local_envvar(list(R_QUARTO_QUIET = NA))
2728
expect_identical(is_quiet(TRUE), TRUE)
2829
expect_identical(is_quiet(FALSE), FALSE)
2930
expect_identical(is_quiet(NA), FALSE)
@@ -63,6 +64,7 @@ test_that("R_QUARTO_QUIET options takes over", {
6364
})
6465

6566
test_that("quarto.quiet options takes over R_QUARTO_QUIET", {
67+
withr::local_envvar(list(R_QUARTO_QUIET = NA))
6668
withr::with_options(list(quarto.quiet = TRUE), {
6769
withr::with_envvar(list(R_QUARTO_QUIET = FALSE), {
6870
expect_identical(is_quiet(TRUE), TRUE)

0 commit comments

Comments
 (0)