Installing R and Updating Packages (with sed and Perl fun)

R is a language and environment for statistical computing and graphics. To install R download the tarball to an appropriate place and extract e.g.,

cd /usr/local/SRC/R
tar xvf R-2.11.1.tar.gz

Load gcc environment modules or use the system defaul. Change into the directory and configure, make and make install. Note that our configure script is designed to automatically install with an appropriate prefix and for shibboleth. i.e.,

install=$(basename $(pwd) | sed 's%-%/%')
./configure --prefix=/usr/local/$install-gcc --with-lapack --with-blas --enable-

module load gcc
make install

Modify the environment modules for the new version. e.g.,

cd /usr/local/Modules/modulefiles/R
ln -s .base 2.11.1

Now for the fun part; ensuring that the optional libraries in the previous version are available for users in the new version.

First we collect the library list from the previous version.
Then we append that with the what has been installed.
Then we sort the list, because we like to be neat (sort).
Then we remove any doubles (uniq).
Then we add double quotes at the beginning and end of each line.
Then, with Perl, we remove line breaks.
Then we load the packages within R.

  • ls /usr/local/R/2.11.0-gcc/lib64/R/library --width="1" >> library.list
  • ls /usr/local/R/2.11.1-gcc/lib64/R/library --width="1" >> library.list
  • sort -u -o library.list library.list
  • sed -i 's/^/"/' library.list
  • sed -i 's/$/", /' library.list
  • perl -pi -e 'tr/[\012\015]//d' library.list.2
  • Login to the cluster, module load the new version of R
  • chooseCRANmirror() - select Australia of course.
  • Install the packages from library.list.2 e.g.,

    install.packages(c("abind", "acepack", "AER", "akima", "anchors", "aplpack", "ash", "base", "biglm", "bitops", "boot", "car", "caTools", "chron", "class", "cluster", "coda", "codetools", "coin", "colorspace", "cubature", "DAAG", "datasets", "DBI", "degreenet", "Design", "dynlm", "e1071", "effects", "ellipse", "ergm", "fBasics", "fCalendar", "fEcofin", "flexmix", "foreach", "forecast", "foreign", "Formula", "fracdiff", "fSeries", "fts", "ftsa", "fUtilities", "gdata", "gee", "gplots", "graphics", "grDevices", "grid", "gtools", "hdrcde", "hexbin", "Hmisc", "HSAUR", "ineq", "ipred", "iterators", "its", "kernlab", "KernSmooth", "kinship", "ks", "latentnet", "lattice", "leaps", "lme4", "lmtest", "locfit", "logspline", "MASS", "Matrix", "maxLik", "mboost", "mclust", "MCMCpack", "MEMSS", "methods", "mgcv", "mice", "mitools", "mix", "mlbench", "mlmRev", "mlogit", "modeltools", "multcomp", "multicore", "mvtnorm", "network", "nlme", "nnet", "numDeriv", "nws", "oz", "party", "pcaPP", "plm", "pscl", "quadprog", "quantreg", "rainbow", "randomForest", "Rcmdr", "RColorBrewer", "R.css", "relimp", "rgenoud", "rgl", "Rglpk", "rlecuyer", "rmeta", "robustbase", "ROCR", "rpart", "RSQLite", "RUnit", "sampleSelection", "sandwich", "scatterplot3d", "sem", "sgeostat", "shapes", "slam", "sna", "snow", "SparseM", "spatial", "splines", "statmod", "statnet", "stats", "stats4", "strucchange", "subselect", "survey", "survival", "systemfit", "tcltk", "tcltk2", "TeachingDemos", "timeDate", "timeSeries", "tis", "tkrplot", "tools", "tree", "tripack", "tseries", "tweedie", "urca", "utils", "vcd", "VGAM", "xtable", "xts", "Zelig", "zoo"))
  • Exit with quit()
  • Go back to /usr/local/Modules/modulefiles/R and change .version