Update all packages from GitHub

This works for me. It goes through all of the packages in your library, not only loaded packages.

update_github_pkgs <- function() {

  # check/load necessary packages
  # devtools package
  if (!("package:devtools" %in% search())) {
    tryCatch(require(devtools), error = function(x) {warning(x); cat("Cannot load devtools package \n")})
    on.exit(detach("package:devtools", unload=TRUE))
  }

  pkgs <- installed.packages(fields = "RemoteType")
  github_pkgs <- pkgs[pkgs[, "RemoteType"] %in% "github", "Package"]

  print(github_pkgs)
  lapply(github_pkgs, function(pac) {
    message("Updating ", pac, " from GitHub...")

    repo = packageDescription(pac, fields = "GithubRepo")
    username = packageDescription(pac, fields = "GithubUsername")

    install_github(repo = paste0(username, "/", repo))
  })
}

library(devtools)

#' Update all github installed packages.
#'
#' This will trash any non-master branch installs, and spend time re-installing
#' packages which are already up-to-date.
update_github <- function() {
  pkgs = loadedNamespaces()
  print(pkgs)
  desc <- lapply(pkgs, packageDescription, lib.loc = NULL)
  for (d in desc) {
    message("working on ", d$Package)
    if (!is.null(d$GithubSHA1)) {
      message("Github found")
      install_github(repo = d$GithubRepo, username = d$GithubUsername)
    }
  }
}

# test it:
# install github version of tidyr
install_github("hadley/tidyr")
library(tidyr)
update_github()

Don't run this if you have any github installations from anything more complicated than the master branch of user/repo. Also be careful if you have a lot of github installations, since this will blindly reinstall them all, even if up-to-date. This could take a long time, and also might break working packages if github master branches are not in tip top condition.

Take a look at devtools R/session_info.r for details.

Tags:

R

Github