Wednesday, November 14, 2012

My way of upgrading R

There's one task that I hate to do in R … INSTALL A NEW VERSION!

With a couple of new releases coming out every year, it's easy to become outdated.

R 2.15.2 has recently been released and this time I decided to do some research on how to easily upgrade R installations.

Packages

Over the years the number of packages I use regularly has grown and I like to keep them whenever I upgrade R.

That's how I do it nowadays.

#----------------------------------------------------------------------------
# execute on CURRENT system
#----------------------------------------------------------------------------

# get list of installed packages
packages <- subset(as.data.frame(installed.packages()),
                   !Priority %in% c("base", "recommended"),
                   select = c(Package))

# and save it
save(packages,
     file=paste(R.Version()$version.string, "packages.Rdata", sep=' '))
Then I install the new version of R and there I do the following.

#----------------------------------------------------------------------------
# upgrade R and
# execute on NEW system
#----------------------------------------------------------------------------

# load list of additional packages
load("R version 2.15.0 (2012-03-30) packages.Rdata")

# and install them
install.packages(packages$Package, dependencies = TRUE)
As can be seen I already had missed the last upgrade :).