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
Prof Brian Ripley
2004-Nov-02 21:08 UTC
[R] install.packages, bundles, pmatch, and Rprofile...
On Tue, 2 Nov 2004, Andy Bunn wrote:> 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.You do want an exact match. The code you need is in packageStatus(), so you don't need to reinvent this particular wheel. Look at its summary() method (and output) to see how to get what you want. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595