resinstalling packages in R after update

R
Author

Michael

Published

April 14, 2011

This is old - by should still work :) - comment on how to do this in 2019 below …

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:

  1. run in the old version of R

packages <- installed.packages()[,"Package"] 
save(packages, file="Rpackages") `
  1. Install new R version
  2. run in the new version
load("Rpackages")
for (p in setdiff(packages, installed.packages()[,"Package"]))
install.packages(p)

At the end of the day this is outdated - with the new RStudio version you can simply add your packages with library() and then simply click on install packages in the RStudio interface.