[R] install.packages, bundles, pmatch, and Rprofile...

Andy Bunn abunn at whrc.org
Tue Nov 2 21:25:59 CET 2004


Hi,

Somebody asked me to make sure that all the machines running the in our lab
(XP and Linux, both running 2.0) have R installed and that A) All the
packages are installed and B) kept up-to-date.

Obediently, I began to modify a shared Rprofile so that once a week it
checks for new packages and updates to the current version of the installed
packages on CRAN. Sounds simple enough. Plus some general conditioning
statements to make sure that this runs only once a week or so the logic I'm
following is:


myPackages      <- installed.packages()
CRANsPackages   <- CRAN.packages()
missingPackages <- CRANsPackages[is.na(match(CRANsPackages[,1],
myPackages[,1])),1]
install.packages(missingPackages)


Now this might be trivial, but, missingPackages includes bundled packages
which are already installed (e.g., dse, VR) in addition to those packages
that are truly missing. I know I have to match myPackages with the Contains
column in CRANsPackages and probably use pmatch to do it, but the syntax
eludes me.

So, an example:
# Install a bundled package
install.packages("gregmisc")
# Get the installed package matrix
myPackages      <- installed.packages()
# See if gregmisc is really there
myPackages[grep("gregmisc", myPackages[,5]),]
# Get the matrix of all the packages on CRAN
CRANsPackages   <- CRAN.packages()
# Find the missing packages
missingPackages <- CRANsPackages[is.na(match(CRANsPackages[,1],
myPackages[,1])),1]
# Whoops, gregmisc is in there even though its bundles are in myPackages...
missingPackages[grep("gregmisc", missingPackages)]
# Here are the bundles as a string in CRANsPackages...
CRANsPackages[grep("gregmisc", CRANsPackages[,1]),8]


I've looked through R-admin and searched CRAN. What I'm after is a
semi-permanent fix to maintaining R on multiple machines and across
platforms. Other folks must do this? Are there other useful tips?

Off to the polls,
Andy




More information about the R-help mailing list