On Mac, I find that in a 'fresh' installation there is no user library and packages are all installed in the version-specific system library. Eventually, a user library is created (possibly accidentally or via an RStudio prompt) and is set to the default location for future package installations. So, if you're not paying close attention you end up with some packages installed in the system library and some in the user library.
The user library is listed first and the system library is listed second:
.libPaths()
> [1] "/Users/<username>/Library/R/3.6/library"
> [2] "/Library/Frameworks/R.framework/Versions/3.6/Resources/library"
I like to keep everything in one place (the system library), so to accomplish this (permanently) I do the following:
In a Terminal window, create a .Rprofile
file in your user directory:
nano ~/.Rprofile
In that file, add the following line of R code:
.libPaths( c(.libPaths()[2], .libPaths()[1]) )
Alternatively, add a similar line of R code but with hardcoded paths:
.libPaths( c("/Library/Frameworks/R.framework/Versions/3.6/Resources/library", "/Users/<username>/Library/R/3.6/library") )
Replace <username>
with your actual username. Then Ctrl-O
(save) and Ctrl-X
(exit) that file.
Either line switches the order of the paths listed above, so that path [2]
(system) is first (Default) and path [1]
(user) is second.
Importantly, by putting this line of code in your user's .Rprofile
it will be run every time R starts and you (hopefully) won't have to worry about this again.