[BioC] Upgrading R

Steve Lianoglou mailinglist.honeypot at gmail.com
Mon May 11 17:25:42 CEST 2009


Hi,

On May 11, 2009, at 10:46 AM, Michal Blazejczyk wrote:

> Hi everyone,
>
> I think an interesting feature in R would be "package list dump"  
> option.
> The way I see this working is the following: the user would issue
> a command on the source R installation (say, an older version), e.g.
>  packages.dump("~/R/packages.dump")
> Then the user would run the destination installation (say, a new  
> version)
> and recreate the environment by issuing a command like:
>  packages.load("~/R/packages.dump")
> This last command would go and download and install all packages that
> were listed in the dump.


This is already possible with a little coding on your part, and is all  
written up in a blog post[1] that I linked to in reply to Kumar's  
question, which I just noticed I sent directly to Kumar w/o CC-ing the  
BioC list ... sorry.

Anyway, I've extracted the code from the post into some functions  
using nomenclature similar to what you're asking for:

========================

packages.dump <- function(dump.file) {
   tmp <- installed.packages()
   installed.old <- as.vector(tmp[is.na(tmp[,"Priority"]), 1])
   save(installed.old, file=dump.file)
}

packages.load.R <- function(dump.file) {
   # Attempts to install all packages that were present in old install
   # into the new install. All non-cran package will return a warning
   # that they are not available, but will allow for the remainder
   # of packages to be installed
   load(dump.file)
   tmp <- installed.packages()
   installed.current <- as.vector(tmp[is.na(tmp[,"Priority"]), 1])
   missing.packages <- setdiff(installed.old, installed.current)
   install.packages(missing.packages)
}

packages.load.bioc <- function(dump.file) {
   # assumes that whatever packages are missing from old install and
   # current install are BioC packages
   load(dump.file)
   tmp <- installed.packages()
   installed.current <- as.vector(tmp[is.na(tmp[,"Priority"]), 1])
   missing.packages <- setdiff(installed.old, installed.current)
   source("http://bioconductor.org/biocLite.R")
   biocLite(missing.packages)
}

===========================

Now, when upgrading R, all you have to do is:

1. Before upgrading, run `packages.dump('/path/to/dumpfile.rda')
2. Install new R
3. Start new R and run `packages.load.R('/path/to/dumpfile.rda')
4. Run `packages.load.bioc('/path/to/dumpfile.rda')`

This assumes that all of the packages in your current installation can  
be downloaded from CRAN, or are otherwise bioconductor packages. If  
this isn't true, it's rather simple to add a function to install  
whatever else you need to (or make one clever `packages.load` function  
that tries to install packages from several different repos and merge  
steps 3 and 4 into one func call).

Anyway, hope that helps.

-steve

[1] Original blog post: http://onertipaday.blogspot.com/2008/10/r-upgrade-on-mac-os-x-1055-leopard.html

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

http://cbio.mskcc.org/~lianos



More information about the Bioconductor mailing list