Update R packages

The simplest way to update packages to their latest CRAN version is:

options(repos = "https://cloud.r-project.org")
pkgs <- c("data.table", "dplyr")
old_pkgs <- old.packages()[, "Package"]
for (pkg in pkgs) if (pkg %in% old_pkgs) install.packages(pkg)

To version control packages, there is a number of techniques available (such as packratcheckpoint). Here is a recommended lightweight alternative on the Saagie platform:

options(repos = "https://cloud.r-project.org")
if (!length(find.package("remotes", quiet = TRUE))) install.packages("remotes")
versions <- c(data.table = "1.10.0", dplyr = "0.5.0")
for (pkg in names(versions)) 
  if (!length(find.package(pkg, quiet = TRUE)) || packageVersion(pkg) != versions[pkg]) 
    remotes::install_version(pkg, versions[pkg])