Some quick tips on upgrading R

I recently took the plunge to upgrade R to 2.15.  As I was pondering the best way to install all my favorite packages, I stumbled upon this very helpful post from HLPlab

http://hlplab.wordpress.com/2012/06/01/transferring-installed-packages-between-different-installations-of-r/

The post describes a very handy way of ensuring that all your favorite packages make it to your new install.  Basically this is done via a handy set of code, and involves: 1) saving the names of your packages to a location, and then 2) calling R to then install those packages by name into your new version.

The code with descriptions can be found below:

1. Run the script “store_packages.R” in your current version of R.

# store_packages.R # # stores a list of your currently installed packages

tmp = installed.packages()

installedpackages = as.vector(tmp[is.na(tmp[,"Priority"]), "Package"])

save(installedpackages, file="packagenames.rda")

Make sure that all the quotation marks in the script are straight.  The scripts will generate an error if they include any curly quotation marks.  For some reason, when I saved this blog entry, some quotation marks changed to curly ones.  WordPress is probably to blame for this problem, which I have not been able to fix.)

2. Close R.  Open the installation of R that you want the packages to be installed in.

3. Run the script “restore_packages.R”.

# restore_packages.R # # installs each package from the stored list of packages

load(“~/packagenames.rda”)

for (count in 1:length(installedpackages)) install.packages(installedpackages[count])

Note that if you want to install the list of packages in an installation of R on a different computer, you should transfer the .rda file that is created by the store_packages script to that computer, and make sure that the path for the “load” command in the restore_packages script is set to the right location.

However, for me, this all may change with my next upgrade–perhaps, as I chose the option to save my packages to a personal library (when 2.15 gave me the option) and my packages are now stored in a different location:

The downloaded binary packages are in
C:\Users\Chris\AppData\Local\Temp\RtmpiCX9N6\downloaded_packages

Advertisements

3 thoughts on “Some quick tips on upgrading R

  1. As an example (just recently re-upgraded), here is what my current installedpackages vector looks like:

    c(“bibtex”, “bitops”, “brew”, “car”, “caTools”, “coin”, “colorspace”,
    “compare”, “data.table”, “devtools”, “dichromat”, “digest”, “directlabels”,
    “doBy”, “evaluate”, “expsmooth”, “fastmatch”, “fields”, “fma”,
    “forecast”, “formatR”, “fpp”, “fracdiff”, “gdata”, “ggmap”, “ggplot2”,
    “gmodels”, “googleVis”, “gplots”, “gRain”, “gRbase”, “gridExtra”,
    “gtable”, “gtools”, “Hmisc”, “httr”, “igraph”, “knitcitations”,
    “knitr”, “labeling”, “LearnBayes”, “lmtest”, “mapproj”, “maps”,
    “markdown”, “memoise”, “modeest”, “modeltools”, “multcomp”, “munsell”,
    “mvtnorm”, “odfWeave”, “party”, “PerformanceAnalytics”, “plyr”,
    “png”, “proto”, “psych”, “quadprog”, “R.devices”, “R.methodsS3”,
    “R.oo”, “R.rsp”, “R.utils”, “R2HTML”, “R2PPT”, “RColorBrewer”,
    “rcom”, “Rcpp”, “RcppArmadillo”, “RcppEigen”, “RCurl”, “reports”,
    “reshape2”, “RgoogleMaps”, “rJava”, “rjson”, “RJSONIO”, “rms”,
    “RODBC”, “rscproxy”, “sandwich”, “scales”, “snow”, “spam”, “stargazer”,
    “stringr”, “strucchange”, “timeDate”, “timeSeries”, “triangle”,
    “tseries”, “vcd”, “whisker”, “XLConnect”, “XLConnectJars”, “xlsReadWrite”,
    “XML”, “xtable”, “xts”, “zoo”, “manipulate”, “rstudio”)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s