.libPath() changes between packages

Hi guys,

I'm developing some R packages and noticed some really strange behavior. I'm not using any virtual environment per package, so each package should have access to the same installed libraries. However,
there are different possible library paths where R might look for packages: So generally, when I run
.libPaths() inside an opened package, I get the following output:

> .libPaths()
[1] "/home/tom/R/x86_64-pc-linux-gnu-library/4.2"
[2] "/usr/local/lib/R/site-library"                 
[3] "/usr/local/lib/R/library"

Now the strange part comes. For a couple of packages, the second entry is missing when I run the command, within the opened project:

> .libPaths()
[1] "/home/tom/R/x86_64-pc-linux-gnu-library/4.2"              
[2] "/usr/local/lib/R/library"

This leads to import errors as R is not able to find the libraries that are stored within /usr/local/lib/R/site-library. I really don't get it why the output of libPaths gives two different results, as the package structure of the two packages is identical. Furthermore, in my understanding libPath is s.th. that is set globally and not per project, at least of no renv is used, right?

Any ideas what is going on here?

I am afraid you'd have to tell us exactly what you are doing, and what platform, IDE, etc. you are using. E.g. what does

mean?

Hey,

thanks for replying.

I'm working with R 4.2.1 on Posit Workbench 2023.03.1+446.pro1, “Cherry Blossom”.
So when I simply start a new session, no project is selected e.g.
In this case,

> .libPaths()
[1] "/home/tom/R/x86_64-pc-linux-gnu-library/4.2"
[2] "/usr/local/lib/R/site-library"                 
[3] "/usr/local/lib/R/library"

With opening a package I mean that I have a running session with a opened project, so that the GUI shows s.th. like this:The project itself is a R package (No Shiny), with the following structure
image

When I now run .libPaths() i get

[1] "/home/tom/R/x86_64-pc-linux-gnu-library/4.2"              
[2] "/usr/local/lib/R/library"

How is this possible, as I though that without using any renv, .libPaths() should always return the same paths.

That is very weird indeed, and probably specific to RStudio, so it would be a good idea to add the RStudio IDE tag to this post, so the right people see it.

I did a quick search, and did not find any (open or closed) issues about this in the issue tracker at Issues · rstudio/rstudio · GitHub so if you don't get a solution here, consider opening an issue there.

FWIW I cannot reproduce this on macOS with RStudio 2023.09.1+494, but I also don't see anything in my project or global settings that could influence this.

Seems like you have an empty .RData file, maybe try removing that, but this is really just a shot in the dark.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.