Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I like that R updates frequently to give me the best new packages, but it does seem to pose a problem for my R scripts on cron schedules.

I noticed that every time ubuntu updater updates my r-base package, when I try to run my scripts, it'll say something like "there is no library(XML)".

Then I have to go "update.packages("XML")" to get the new version of that package that is compatible with my new version of R.

I have a lot of packages installed, so I find myself fairly regularly tracking them down and making long commands like "update.packages(c("XML", "ggplot2", "timeseries"))".

When I forget to do this after an update, all my R cron scripts fail.

Does anyone have a good workflow for automatically checking which packages I have already installed, and updating them when they need to be updated?

share|improve this question
up vote 4 down vote accepted

You could add an install.packages() call in your cron script, so that it installs all current packages before it runs the rest of your R cron jobs.

install.packages takes a vector, so you could even keep the file with the packages you want installed elsewhere and then load it automatically in your cron update script.

installed.packages() returns a vector of already-installed packages, so you can use %in% to just call it on packages not yet installed:

desired.packages <- c("plyr","taRifx","ggplot2")
missing.packages <- ! desired.packages %in% installed.packages()[,1]
if( any(missing.packages) ) { 
   install.packages( desired.packages[missing.packages] )

Edit: Possibly better solution

As per @JoshuaUlrich's suggestion in chat:

Place this in your .Rprofile.


Then you should be able to just run update.packages() after Ubuntu wipes everything, and the monarchy will be restored.

This solution requires greater caution that packages that don't work with the current version of R aren't carried along.

share|improve this answer
Yeah, thanks, that will likely do it. Also, Josh Ulrich remains a very helpful super wizard. – Mittenchops May 31 '12 at 18:49
@Mittenchops Indeed. Between hadley() and JU(), my problems solve themselves these days. :-O – Ari B. Friedman May 31 '12 at 19:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.