diff --git a/R/quarto.R b/R/quarto.R index c66f555..c81c32a 100644 --- a/R/quarto.R +++ b/R/quarto.R @@ -147,10 +147,18 @@ quarto_run <- function( # (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) - ) + libs_val <- paste(libpaths, collapse = .Platform$path.sep) + custom_env <- c(custom_env, R_LIBS = libs_val) + + # On Windows, also point R_ENVIRON_USER at a temp Renviron that re-sets + # R_LIBS. The user Renviron is processed after the site Renviron, so this + # wins over any system-level reset of R_LIBS during R startup. + # https://github.com/quarto-dev/quarto-r/issues/217 + if (.Platform$OS.type == "windows") { + environ_file <- tempfile("quarto_renviron_", fileext = "") + writeLines(sprintf("R_LIBS=%s", libs_val), environ_file) + custom_env <- c(custom_env, R_ENVIRON_USER = environ_file) + } } # This is required because `"current"` only is not supported by processx diff --git a/tests/testthat/test-quarto.R b/tests/testthat/test-quarto.R index 9111563..d39e829 100644 --- a/tests/testthat/test-quarto.R +++ b/tests/testthat/test-quarto.R @@ -161,9 +161,6 @@ test_that("quarto_available()", { 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")