Reputation: 5696
I have observed that R
installation in Windows creates two library paths automatically.
.libPaths()
# [1] "C:/Users/User/Documents/R/win-library/3.4"
# [2] "C:/Program Files/R/R-3.4.0/library"
What is the use of these while installing new packages and which library is used? I have frequently observed the installed packages being missed and need to install again. How do you maintain these two paths and manage the libraries while using R
or RStudio
in Windows?
Upvotes: 3
Views: 3739
Reputation: 4077
Installing into C:/Program Files/R/...
makes a package available to all users of the computer.
It is the R default, but installing a package there from within R (using install.packages()
requires that R is started with administrator privileges.
Installing into C:/Users/Username/...
makes the package available to the present user only, but does not require administrative rights.
R tracks these paths automatically, and looks in both directories when it is asked to load a package with require()
or library()
. No user input should be required.
When you update R, the version number will of course change, meaning that R will no longer look in the folders whose paths contained the previous version number. Some R updaters (e.g. installR) offer to copy packages from the "old" paths to the "new" paths, though an manually re-installing packages means that you can be sure that you are using the latest version of each package, and that you don't waste disk space and update time on packages that you are no longer using.
Upvotes: 3