The R script that will change your life

May 3, 2013    r programming rprofile automation updating packages

If you use the R programming language, you probably know how much of a pain it is to keep your packages updated. You’ve run update.packages(...) on the few that you want to keep up to date, but it’s a pain in the neck to do that for every package, every time. Thankfully, where there’s a will, there’s a way!

When R starts up, it looks at your .Rprofile file (if you have one), and runs it. Mine looks like this:


update.packages(ask = FALSE)
my.packages = c("CvM2SL2Test", "MASS", "verification", "gtools", "ROCR",
        "RColorBrewer", "", "gmodels", "gplots",
        "profr", "proftools",
        "colorRamps") = which(!my.packages %in% rownames(installed.packages()))
if( length( > 0){
    install.packages(my.packages[], clean=TRUE, dependencies=TRUE)

This script has three awesome features:

  1. It will update ALL the packages I have without asking.
  2. It has an A-list of packages that I always want to have.
  3. It iterates over the A-list and makes sure they’re updated.

It may be a little redundant, but having a few fail-safes never hurt anyone.

Feel free to steal this .Rprofile for your own usage.

comments powered by Disqus