The R library folder on a Mac

How do you update your R? I mean the whole thing, not just the base packages.

R comes with a library folder where packages go -- both the base packages and the user-written ones you install over time. I'm not entirely sure what would be the best place for this folder so updates to all packages are as easy as possible.

It gets worse. On a Mac you have not one, but n+2 library folders. One is /Library/Frameworks/R.framework/Resources/library. Let's call it (1). The other n+1 are as many as there are historic versions of R on your computer, plus one. All are in /Library/Frameworks/R.framework/Versions/. In my case, they are as follows: n of them are in X/Resources/library, where X is 2.13, 2.14, and 2.15; one is in Current/Resources/library.

I know that the three library folders in X=2.15, Current and (1) are identical and updated simultaneously, though only the first shows up when I call .libPaths(). But when you update say, from 2.15 to 2.16, your historic versions remain frozen and the new (1) and Current folders reflect only 2.16. You have to install non-base packages all over again, by hand. Or do you? Is there a way to script an update of everything in the library folder at version t-1 when you update your R to version t? If anybody knows, please drop a comment. Thank you.

5 Responses to “The R library folder on a Mac”

  1. chl writes:

    You can define `R_LIBS=/Library/Frameworks/R.framework/Rlibs` in your `~/.Renviron`, and make it point to your local library of non-base packages. Of note, if you are working with different versions of R, you might get some warnings when updating packages (e.g., packages compiled and tested again latest release of R will likely issue some warnings when loaded under an older version of R).

  2. Gabi Huiber writes:

    That would solve the problem, because it would keep updates from forgetting about existing non-base packages. But to do this, if my base and non-base packages are now all in the same library folder, do I have to separate them somehow and send the non-base ones to this new Rlibs folder? If so, how do I do that? I looked at installed.libraries(). It's an 89x12 character matrix. Its fourth column tells the Priority, so it should be easy to isolate the packages where Priority=="base". But it's not. Doing basepacks < - as.matrix(installed.packages()[!is.na(installed.packages()[,4]=="base"),1]) produces a character matrix of one column whose row labels are copies of the element values. It looks strange.Typical R rabbit hole, and this should be easy housekeeping stuff. Thanks for stopping by.

  3. chl writes:

    R won't update base packages. You can install a new version of R, say 2.15, and keep working with packages installed under the 2.14 directory tree (e.g., y adding a symlink, say Rlibs, pointing /Library/Frameworks/R.framework/Versions/2.14/Resources/library). An alternative solution is to use the devtools packages, by Hadley Wickham (https://github.com/hadley/devtools/): Everything get installed into a custom folder on your HD.

  4. Gabi Huiber writes:

    I went with the ~/.Renviron solution that Christophe suggested, and hit some new trouble. RStudio insists on considering both my custom library path and the original one, as shown in the .libPaths() output below:

    
    > .libPaths()
    [1] "/Users/ghuiber/Rlibs"                                           
    [2] "/Library/Frameworks/R.framework/Versions/2.15/Resources/library"
    [3] "/Applications/RStudio.app/Contents/Resources/R/library"
    

    This is a problem, because updating packages in RStudio now takes twice as long (both [1] and [2] above are updated) and the bottom-right pane in RStudio now lists each package twice. I wonder if anybody has any ideas how to make RStudio just go by [1], the library set by ~/.Renviron.

  5. Setting up my R library folder on a Mac | The Stata Things writes:

    [...] folders, I created this .Renviron file as instructed by Christophe Lalanne in the comments to my earlier post on the [...]

Leave a Reply