My understanding is that there are three kinds of R packages: base, recommended, and everything else. You can tell which is which by inspecting the output of installed.packages(). That is easiest done in RStudio by sending that output to a data frame, like this


packs <- as.data.frame(installed.packages())

You can see that this data frame has a column named Priority. The output of table(packs$Priority, exclude=NULL) shows that I have 14 base packages, 15 recommended ones, and 70 of the other kind -- user-contributed kit that I installed over time as I bumbled my way through learning and using R.

Looking at packs in the top left pane of Rstudio also shows that the rows are named after the packages. This means that you can collect the names of base and recommended packages easily:


> names(subset(packs, Priority=="recommended")$Package)
 [1] "boot"       "class"      "cluster"    "codetools"  "foreign"    "KernSmooth"
 [7] "lattice"    "MASS"       "Matrix"     "mgcv"       "nlme"       "nnet"      
[13] "rpart"      "spatial"    "survival" 

Having all the R packages in the same default library, which is /Library/Frameworks/R.framework/Versions/2.15/Resources/library as of this writing, comes with the disadvantage that when I upgrade to the next version of R I will have to re-install the 70 packages of the third kind.

It would be nice if I could set them aside in a different library, and any future version of R will know to look for them there and update them as needed.

There are two steps to this job: one is the actual moving of package folders; the other is to show R where to look for them.

First, I created a new folder called Rlibs. Then I moved the folders around with this Bash script, which I called movePacks.sh:


#!/bin/bash

# declare an array with the names of the base packages
basepacks=("base" "compiler" "datasets" "graphics" "grDevices" "grid" "methods" "parallel" "splines" "stats" "stats4" "tcltk" "tools" "utils")

# and another with the names of the recommended ones
recpacks=("boot" "class" "cluster" "codetools" "foreign" "KernSmooth" "lattice" "MASS" "Matrix" "mgcv" "nlme" "nnet" "rpart" "spatial" "survival")

# and now concatenate them
allpacks=("${basepacks[@]}" "${recpacks[@]}")

# where you're moving from
oldLib="/Library/Frameworks/R.framework/Versions/2.15/Resources/library"

# where you're moving to
newLib="/Users/ghuiber/Rlibs"

# first, move everything over
mv ${oldLib}/* ${newLib}

# then move the base and recommended packages back to their default location
for i in "${allpacks[@]}"
do
   mv ${newLib}/${i} ${oldLib}
done

Finally, to point R to the library folders, I created this .Renviron file as instructed by Christophe Lalanne in the comments to my earlier post on the topic:


R_PAPERSIZE=letter
R_LIBS=/Users/ghuiber/Rlibs
EDITOR=vim

The ideas for the R_PAPERSIZE and EDITOR environment variables came from here.