I'd like to move several R libraries (*) from one drive to another, on Linux, and would like to know whether a simple move is feasible and safe or if I should uninstall and reinstall the packages. I realize that the locations of libraries are identified via .libPaths()
and have looked through the "R Installation and Administration" manual to find out about migrating libraries, but don't see a recommended process.
I perceive three options:
- Run
remove.packages()
for all of the non-base packages, and install anew via install.packages(lib = "/path/to/new/location")
.
- Move the libraries (directories) using
mv
and use symlinks to point to the new locations (and eventually remove the symlink)
- Use the
mv
command in Linux to move the directories wholesale and update .Library.site
in R_HOME/etc/Rprofile.site
, as suggested in the R Installation and Administration manual
Option #1 is blunt. Option #2 should work, but seems a bit unsound.
Is #3 safe or are there serious problems with it? The issues I've identified are: directory permissions and the possibility that any package's setup stores absolute paths rather than relative paths (which seems unsound and unnecessary).
Regarding the storage of absolute paths, I found that rJava
stores the location of R_HOME
in a file called run
. This isn't a library problem per se, but it is one indication of a package (and a good package at that) keeping a private copy of an absolute path.
(*) There are several libraries and many scores of packages. Naturally, just the libraries (directories) are moved, but packages could be affected.
UPDATE 1 / Clarification: Just to clarify: I am only migrating libraries, not changing the version of R or the versions of the packages. Updating R or the packages may be done separately, but the question is just whether or not moving the libraries is feasible. It seems that if it is necessary to update or reinstall all packages in order to be sure things are installed correctly, then that is a path more akin to option #1 than option #3.
UPDATE 2: Answers to another SO post have some good ideas on how to avoid this problem when upgrading. I'm not upgrading R, but Dirk Eddelbuettel's suggestion of not installing packages in the filetree of R is wise.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…