Jason A. French

Northwestern University

Installing Old R Packages for New Installations

| Comments

New versions of R are pushed frequently to fix bugs and address performance concerns. However, in order to avoid conflicts between R and packages that were compiled for older versions of R, every upgrade defines a new system and user library location in which to install packages (e.g., /Library/Frameworks/R.framework/Versions/3.1/).
So how does one avoid installing each package manually?

I wrote the following code for my lab to automate the re-installation of an R system library after version upgrades. It reads the old package names into R as a list and recompiles each packages for the new version of R, when available.

Re-installing R packages for newer versions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env Rscript
# Automatic Package Reinstallation
# Author:  Jason A. French, Northwestern University
# GPL v2.0

# Replace the 3.1 with your old version
versions <- system('ls /Library/Frameworks/R.framework/Versions/', intern = TRUE)
previous.version <- sort(versions[-which(versions=='Current')])[length(sort(versions[-which(versions=='Current')])) - 1]
full.dir <- paste('/Library/Frameworks/R.framework/Versions/',
                  previous.version,
                  '/Resources/library/',
                  sep = '')
packages <- system(paste('ls', full.dir), intern = TRUE)

lapply(X = packages, function(x){install.packages(x, type = 'source')})

update.packages(ask = FALSE)

Comments