# Updating R but keeping your installed packages

June 28, 2012
By

(This article was first published on Recipes, scripts and genomics, and kindly contributed to R-bloggers)

This is probably an issue that has been addressed by many blog posts (including these ones: [link1] and [link2]), and can be deduced from R Installation and Administration manual. However, I will post it here for future reference. The problem is that when you update R you usually need to re-install your libraries or change .libPaths() to point to a location that has your previous libraries.

The solution below will work for unix-like operating systems including Mac OS X.

First, we need a location to install all our packages from now on. This can be any directory, and location of this directory should be indicated in ~/.Renviron file. Let's create that directory now:

mkdir ~/Rlibs

We created Rlibs directory in our home directory. Now, create the .Renviron file in your home directory and enter the following line and save the .Renviron file:

R_LIBS=~/Rlibs

We can now start R and install any library. The libraries will be installed to ~/Rlibs, and when we update R, R will still look for libraries in ~/Rlibs directory so we don't need to re-install the libraries. However, we will need to update the libraries in ~/Rlibs directory to their most recent versions. All we need to do is to run update.packages() in R console, and the libraries will be updated.

You can also update Bioconductor package as follows (this probably works with newer versions of Bioconductor):

source("http://bioconductor.org/biocLite.R")biocLite("BiocUpgrade")

EDIT:
see here for setting environment variables  in Windows
http://cran.r-project.org/bin/windows/base/rw-FAQ.html#How-do-I-set-environment-variables_003f