I know you can install packages from CRAN with this syntax:
install.packages(c(\"Rcpp\"), dependencies=TRUE)
You can update all of them from CR
2019 update:
The function update_packages()
from the package remotes (one of the "offspring" of devtools) now does a great job at updating packages from CRAN, GitHub, etc.
You might want to set some environment variables to make it work smoothly for you. The README of the package on GitHub gives their list. In my case, this is what I have:
R_REMOTES_UPGRADE=always
R_REMOTES_NO_ERRORS_FROM_WARNINGS=true
GITHUB_PAT=<my GitHub personal access token>
Once set, all you have to do is:
remotes::update_packages()
to update all your packages.
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.
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))
})
}