Update all packages from GitHub

后端 未结 3 1066
暖寄归人
暖寄归人 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条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 19:11

    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.

提交回复
热议问题