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?
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: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.