resinstalling packages in R after update

The new version 2.13.0 of R has just been released and with the update comes the pain of re-installing all the packages from the old installation on the new one.

Stackoverflow to the rescue! This posting provides a simple two step process of first writing a list of packages into a file on the disk in the old version, installing the new version and then comparing the exported list to the currently installed packages in the new version with setdiff. I just went through the process and have to say that it is deadeasy! Below the code …

#--run in the old version of R 
setwd("C:/Temp/") 
packages <- installed.packages()[,"Package"] 
save(packages, file="Rpackages") 

INSTALL NEW R VERSION

#--run in the new version 
setwd("C:/Temp/") 
load("Rpackages") 
for (p in setdiff(packages, installed.packages()[,"Package"])) 
install.packages(p)