Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.libPaths() order changes when rendering .qmd

Tags:

r

quarto

I tried rendering a qmd in which I used a package I manually updated, that is also provided by an R-image already installed.

In my R set-up packages are in 3 different directories. One with base R, one with packages included in an R image and one with manually installed packages. When manually installing newer versions of the packages provided in the R image, loading them usually results in loading the manual installation, as the corresponding directory is the first entry in .libPaths(). However, when rendering a qmd the library search path order seems to get mixed up and I end up with the older package versions from the R image, because they are found first.

To reproduce:

  1. You need a similar set-up where the latest version of readr is in the first directory listed by .libPaths() and an older version of readr is in a library path with lower search order.

  2. Run the code below in a qmd file and then render it.

---
title: "library_paths_example"
format: html
editor: visual
---

```{r}
packageVersion("readr")
.libPaths()
```

You should see that the order and package version differ between the output within the qmd and the rendered html. I am not sure what causes the reordering of the library search paths but I guess you might have to play around with the path directory naming if it does not work right away.

I am using quarto version 1.3.450

like image 985
NicoG Avatar asked Dec 07 '25 16:12

NicoG


1 Answers

As a work around it is possible to pass the library path when calling library() by setting the argument lib.loc = path, i.e. library(readr, lib.loc = path).

like image 105
NicoG Avatar answered Dec 09 '25 14:12

NicoG