Open karltk opened 5 years ago
That's very odd. I wasn't able to reproduce either on macOS or my Ubuntu 18.04 VM.
My best guess is that perhaps you have an R startup profile somewhere that's trying to set the library paths, and that's somehow conflicting with the set of library paths used during package install in the Packrat project.
That's a very good guess! I do indeed call .libPaths
in my ~/.Rprofile
, but I thought that was harmless because
The packrat docs state, on the caveats/limitations page page, that "Any local or site-wide initialization file is overridden.", and
The lib paths looked reasonable to me, from inside the project:
> .libPaths()
[1] "/home/karltk/zzz/packrat/lib/x86_64-pc-linux-gnu/3.5.2"
[2] "/home/karltk/zzz/packrat/lib-ext/x86_64-pc-linux-gnu/3.5.2"
[3] "/home/karltk/zzz/packrat/lib-R/x86_64-pc-linux-gnu/3.5.2"
However, it does indeed appear that the settings in ~/.Rprofile
are being picked up somehow, and that they're messing with the packrat environment. Removing the call to .libPaths
in ~/.Rprofile
resolves the issue.
Our of curiousity, would you happen to know if there's a another way to detect this kind of library path confusion from inside packrat-enabled projects? Evidently, inspecting .libPaths()
isn't enough, because its output is not affected by what I put in ~/.Rprofile
in this case.
My understanding is that during install.packages()
, R invokes the moral equivalent of:
R CMD INSTALL -l <library> <package>
That process should be launched in the current working directory, and so will use whatever startup profile would normally be activated for that path.
To wit, I would only expect the behavior you're seeing if you were calling install.packages()
when not within the project's directory, but I could be wrong.
Hmm. That's what I'm doing. I'm changing directory and starting R inside the packrat-enabled project dir). I've verified that the directory has its own .Rprofile
generated by packrat. But it may be that subprocesses invoked by install.packages
somehow pick up the info from ~/.Rprofile
for some reason.
Anyway, thanks for your kind assistance. Feel free to close this ticket. (You may or may not want to consider adding a small warning / qualification to the caveats section in the docs for others who might fall into the same trap).
For future reference: It appears that a temporary directory is created for each package that is being installed, e.g.
/tmp/RtmpTZXCMH/R.INSTALL498a6ea1eddd/HDF5Array
/tmp/Rtmp67ytex/R.INSTALL49a036c22af8/Rsamtools
/tmp/RtmpJuwIqI/R.INSTALL4a6c6da7f761/doRNG
/tmp/RtmppZ6ONN/R.INSTALL4a7c2976b671/dplyr
and that R is invoked inside of each one of these. As there is no .Rprofile
in these directories, R presumably it falls back to sourcing ~/.Rprofile
, which in my case overwrote the .libPath
.
What if you set Sys.setenv(R_PROFILE_USER = "")
before running the command -- does that work around the issue?
Hi Kevin,
Just wanted to say that I had the same issue and solved by adding: Sys.setenv(R_PROFILE_USER = "") as you suggested before installing packages.
Cheers!
Problem
I am trying to install the R package
pillar
from CRAN using Packrat 0.5.0 on R 5.2.1, but for some reason the installation process breaks because the prerequisite packagecrayon
is not detected even though it was automatically installed byinstall.packages
.Steps to reproduce
Create a dummy directory for a minimal project:
Run the R interpreter inside this directory:
On startup, R acknowledges the Packrat installation:
Try to install the
pillar
package:Verify that the
crayon
library actually exists and is accessible:Environment information
Output from R
sessionInfo
:Output from
cat /etc/lsb-relase
:Output from R:
Discussion
I've tried with
install.packages('pillar', quiet = FALSE, verbose = TRUE)
to dig deeper into the issue, but not found any additional information that I was able to use. It seems such a basic problem that I suspect this might be a PEBCAC-situation, but I've been unable to figure out why thereshape2
package installs just fine, whereas thepillar
package does not.