gpt4 book ai didi

r - 从 GitHub 更新所有包

转载 作者:行者123 更新时间:2023-12-02 02:17:43 26 4
gpt4 key购买 nike

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

install.packages(c("Rcpp"), dependencies=TRUE)

您可以通过以下方式从 CRAN 更新所有内容:

update.packages()

另一方面,您可以使用以下命令从 GitHub 安装包(编译它们):

install_github("hadley/tidyr")

如何升级所有 GitHub 软件包?

我的意思是无需一次重新安装(和编译)它们。类似 github 的 update.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))
})
}

关于r - 从 GitHub 更新所有包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32538052/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com