Update all user installed R packages – again

[This article was first published on Rainer's Blog » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

To leave a comment for the author, please follow the link and comment on their blog: Rainer's Blog » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)