Update all packages from GitHub

后端 未结 3 1067
暖寄归人
暖寄归人 2021-01-31 19:00

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

3条回答
  •  -上瘾入骨i
    2021-01-31 19:18

    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))
      })
    }
    

提交回复
热议问题