Update all user installed R packages – again

And I had to do it again: I am using R installed from homebrew, and after the upgrade from Mavericks to Yosemite, I had to re-install all packages – or was it a GCC upgrade? I don’t know – but I had to do it again.

I still had the link to Randys Zwitch’s solution but I think there were some shortcomings. His solution is as follows:

## Get currently installed packages
package_df <- as.data.frame(installed.packages("/Library/Frameworks/R.framework/Versions/2.15/Resources/library"))
package_list <- as.character(package_df$Package)

## Re-install Install packages
install.packages(package_list)

The shortfalls were:

  • hard coded path to the library
  • I don’t like factors…
  • I want (need) to install from source

So I just revised the script slightly and came up with this solution:

install.packages( 
    lib  = lib <- .libPaths()[1],
    pkgs = as.data.frame(installed.packages(lib), stringsAsFactors=FALSE)$Package,
    type = 'source'
)

Very similar, but, most importantly, the path is not hardcoded.

Hope this helps somebody.

Cheers and enjoy life,

Rainer

P.S: The enjoy life has become more important for me – a friend died in an helicopter crash and he left his wife with two little children. Life is really to short and can end anytime – to precious not be enjoyed. RIP.