Tuesday, September 21, 2010

Install and load R package "Rcmdr" to quickly install lots of other packages

I recently reformatted my laptop and needed to reinstall R and all the packages that I regularly use. In a previous post I covered R Commander, a nice GUI for R that includes a decent data editor and menus for graphics and basic statistical analysis. Since Rcmdr depends on many other packages, installing and loading Rcmdr like this...

install.packages("Rcmdr", dependencies=TRUE)
library(Rcmdr)

...will also install and load nearly every other package you've ever needed to use (except ggplot2, Hmisc, and rms/design). This saved me a lot of time trying to remember which packages I normally use and installing them one at a time. Specifically, installing and loading Rcmdr will install the following packages from CRAN: fBasics, bitops, ellipse, mix, tweedie, gtools, gdata, caTools, Ecdat, scatterplot3d, ape, flexmix, gee, mclust, rmeta, statmod, cubature, kinship, gam, MCMCpack, tripack, akima, logspline, gplots, maxLik, miscTools, VGAM, sem, mlbench, randomForest, SparseM, kernlab, HSAUR, Formula, ineq, mlogit, np, plm, pscl, quantreg, ROCR, sampleSelection, systemfit, truncreg, urca, oz, fUtilities, fEcofin, RUnit, quadprog, mlmRev, MEMSS, coda, party, ipred, modeltools, e1071, vcd, AER, chron, DAAG, fCalendar, fSeries, fts, its, timeDate, timeSeries, tis, tseries, xts, foreach, DBI, RSQLite, mvtnorm, lme4, robustbase, mboost, coin, xtable, sandwich, zoo, strucchange, dynlm, biglm, rgl, relimp, multcomp, lmtest, leaps, effects, aplpack, abind, RODBC.

Anyone else have a solution for batch-installing packages you use on a new machine or fresh R installation? Leave it in the comments!

5 comments:

  1. If the old system is still available you can use

    installed.packages()[,1]

    to get a list of all installed packages. Save it somewhere:

    write.table(installed.packages()[,1], row.names=F, col.names=F, file="Rpackages.txt")

    and pass it as a character vector to install.packages() on the new system to get the same setup.

    ReplyDelete
  2. I have a R-script called "maintenance.R" which I've used to originally install the packages, e.g:

    # Install Bioconductor
    source("http://bioconductor.org/biocLite.R")
    biocLite()

    # Install Bioconductor packages
    source("http://bioconductor.org/biocLite.R")
    biocLite("affyQCReport")
    biocLite("latticeExtra")
    ...

    # Install R-packages
    install.packages("gap")
    install.packages("matlab")
    install.packages("lattice")

    And then I have also commands for updating all installed packages, e.g.:

    #Update R packages
    update.packages(ask=FALSE)

    # Update installed Bioconductor packages
    source("http://bioconductor.org/biocLite.R")
    update.packages(repos=biocinstallRepos(), ask=FALSE)

    ..For me this is very easy way to install and update all the packages, and if I need to set up a new machine, new install of R or whatever, it is really simple to just run that script.

    ReplyDelete
  3. If you use OS X you could refer to:
    http://onertipaday.blogspot.com/2008/10/r-upgrade-on-mac-os-x-1055-leopard.html

    ReplyDelete
  4. I find Robert's solution in principle easier but since I'm just beginning to learn my way with R, may I know how would you pass "Rpackages.txt" as a character vector to the install.packages function?
    Many thanks in advance,
    Ruben

    ReplyDelete
  5. On the new system you can load the package list using read.table or scan:

    packages <- scan("Rpackages.txt", "character")

    Then, to avoid reinstalling packages that are already there, I would use

    install.packages(packages[!(packages %in% installed.packages())], dependencies=T)

    to get all the missing packages in place.

    ReplyDelete

Note: Only a member of this blog may post a comment.

Creative Commons License
Getting Genetics Done by Stephen Turner is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.