rstudio / packrat

Packrat is a dependency management system for R
http://rstudio.github.io/packrat/
401 stars 89 forks source link

Symlinking system packages fails with Hombrew-upgraded R #534

Open slhck opened 5 years ago

slhck commented 5 years ago

I am using R 3.5.2_2 under macOS, installed via Homebrew with Packrat 0.5.0.

When Homebrew upgrades R to a new version, a new library is created, living in /usr/local/Cellar/r/3.5.2_2/lib/R/library, in contrast to the previous one at /usr/local/Cellar/r/3.5.2/lib/R/library.

Issue

When opening a Packrat project that I previously created with an old version of R, I get this error:

In file.symlink(from, to) :
  cannot symlink '/usr/local/Cellar/r/3.5.2_2/lib/R/library/base' to '/Users/werner/Documents/Projects/foo-data-analysis/data-analyze/rscript/packrat/lib-R/x86_64-apple-darwin17.7.0/3.5.2/base', reason 'File exists

And of course these files already exist:

➜ ll lib-R/x86_64-apple-darwin17.7.0/3.5.2/
total 0
lrwxr-xr-x  1 werner  staff  50 Jan  4 16:09 KernSmooth -> /usr/local/Cellar/r/3.5.2/lib/R/library/KernSmooth
lrwxr-xr-x  1 werner  staff  44 Jan  4 16:09 MASS -> /usr/local/Cellar/r/3.5.2/lib/R/library/MASS
lrwxr-xr-x  1 werner  staff  46 Jan  4 16:09 Matrix -> /usr/local/Cellar/r/3.5.2/lib/R/library/Matrix
lrwxr-xr-x  1 werner  staff  44 Jan  4 16:09 base -> /usr/local/Cellar/r/3.5.2/lib/R/library/base
...

They point to the old R library.

Expected behavior

My understanding is that these symlinks should always point to the actual system library, which is correctly printed in .libPaths():

> .libPaths()
[1] "/Users/werner/Documents/Projects/foo-data-analysis/data-analyze/rscript/packrat/lib/x86_64-apple-darwin17.7.0/3.5.2"    
[2] "/Users/werner/Documents/Projects/foo-data-analysis/data-analyze/rscript/packrat/lib-ext/x86_64-apple-darwin17.7.0/3.5.2"
[3] "/usr/local/Cellar/r/3.5.2_2/lib/R/library"

Possible workaround

I can rm -rf lib-R and restart R, then the symlinks will be recreated.

slhck commented 5 years ago

I should add that with the old symlinks present, packrat fails when running packrat::snapshot() with the following error:

Error in lock[, "Package"] : subscript out of bounds