Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 从GitHub更新所有包_R_Github - Fatal编程技术网

R 从GitHub更新所有包

R 从GitHub更新所有包,r,github,R,Github,我知道您可以使用以下语法从CRAN安装软件包: install.packages(c("Rcpp"), dependencies=TRUE) 您可以使用以下命令从CRAN更新所有这些命令: update.packages() 另一方面,您可以通过以下方式从GitHub安装(编译)包: install_github("hadley/tidyr") 如何升级所有GitHub包 我的意思是不需要一次重新安装(编译)它们。类似于github的update.packages()。库(devtools

我知道您可以使用以下语法从CRAN安装软件包:

install.packages(c("Rcpp"), dependencies=TRUE)
您可以使用以下命令从CRAN更新所有这些命令:

update.packages()
另一方面,您可以通过以下方式从GitHub安装(编译)包:

install_github("hadley/tidyr")
如何升级所有GitHub包

我的意思是不需要一次重新安装(编译)它们。类似于github的
update.packages()

库(devtools)
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()
#'更新所有github安装的软件包。 #' #'这将丢弃任何非主分支安装,并花费时间重新安装 #'已更新的软件包。
更新\u github这对我很有用。它将遍历库中的所有包,而不仅仅是加载的包

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

update\u github\u pkgs2019年更新:

包()中的函数
update\u packages()
现在可以很好地更新来自CRAN、GitHub等的包

您可能需要设置一些环境变量,使其能够顺利运行。给出了他们的清单。就我而言,这就是我所拥有的:

R_REMOTES_UPGRADE=always
R_REMOTES_NO_ERRORS_FROM_WARNINGS=true
GITHUB_PAT=<my GitHub personal access token>

更新您的所有包。

我不确定,但是来自
devtools
update\u-packages
可能会有帮助。一般来说,您不能这样做,因为GitHub代码存储库不是R包存储库。因此,@Khashaa善意地指出了这一需求。您在这里指出的是我对
install\u github()
的主要看法。rdocumentation.org知道github和bioconductor上的许多软件包。难道不应该有一种方法来查询这个(或类似的)网站的下载链接吗?也许我遗漏了一点…好吧。谢谢你,杰克。但它说“复制tidyr.dll时出错…”更新itI时,我将尝试使用pkgs[!pkgs==“tidyr”]Hmmm,对我有效。是否有其他错误信息?在新的R会话中是否存在此问题?可能是防病毒软件不允许替换某些文件,或者是Windows,我使用的是W10。没有其他信息。无论如何,在github上更新任何包之前,我无法检查它是否能再次工作。它不会检测到诸如之类的包,而且它说“Username参数已弃用。请使用yihui/knitr”
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))
  })
}