使用devtools::install_github安装的软件包是否有更新检查功能?

11
我是一份存储在 GitHub 上的软件包的作者。我的同事们通过 devtools::install_github() 安装这个软件包。他们想测试一下软件包是否已经更新过。是否有一种函数可以检查自从他们上次安装该软件包以来 GitHub 主干分支上是否有新的提交?
2个回答

2

这是我知道的一种间接方法,您可以通过packageVersion()找到已安装的版本。

有一个名为versions的可用软件包。函数available.versions()可以帮助您。这将找到所有曾经可用的软件包版本。

packageVersion("ggplot2")
#[1] ‘1.0.1’

available.versions("ggplot2")

#$ggplot2
#   version       date available
#1    1.0.1 2015-03-17      TRUE
#2    1.0.0 2014-05-21     FALSE
#3  0.9.3.1 2013-03-02     FALSE
...

更新:

devtools有函数package_deps()和dev_package_deps()。

package_deps("ggplot2")

# Needs update -----------------------------
# package      installed available
# ggplot2      2.0.0     2.1.0    
# scales       NA        0.4.0   

?package_deps
"Find all dependencies of a CRAN or dev package."

{这个函数在我的开发包中没有经过测试。但我相信这应该能完成你的工作。}


1
谢谢,这听起来是一个不错的工具。versions::available.versions() 将“列出CRAN上曾上传的命名软件包的所有过去版本”。因此,这将无法与从Github安装的软件包一起使用。 - Paul Rougieux
@PaulRougieux添加了一个更新。希望对您有所帮助。如果没有,请告诉我。 - GAURAV
你如何指定 dev_package_deps() 函数的 repo 参数以获取 Github 仓库的依赖包?例如,对于 ggplot2 - Paul Rougieux
安装完您的软件包后,请尝试使用以下命令:package_deps("rNVD3", repos = "ramnathv/rNVD3") - GAURAV
但是 package_deps("ggplot2", repos = "hadley/ggplot2") 并不会检查 github 上的 "hadley/ggplot2" 存储库,它只会返回 "Not on CRAN ----"。而 package_deps("ggplot2") 则告诉我根据 CRAN 上可用的信息需要更新的包。在 ?dev_package_deps 中让我困惑的是什么是“dev”包?我猜它是你正在开发的包,而不是托管在 github 上的包。 - Paul Rougieux
package_deps() is part of the package remotes - tic-toc-choc

0
遇到同样的问题,我创建了这个函数,受到devtools::install_github的启发,它可以为我完成工作。据我理解,它会比较已安装包的SHA和github上的SHA。我认为它要求使用devtools::install_github来安装包,但我还没有进行足够详尽的测试。
check_github_sha <- function(username, repo, host = "api.github.com") {
  if (Sys.getenv("GITHUB_PAT") == "") {
    stop('Make sure that you have set a "Personal Acess Token" (PAT) named GITHUB_PAT in .Renviron')
  }
  remote_obj <- remote <- list(
    host = host,
    package = NULL,
    repo = repo,
    subdir = NULL,
    username = username,
    ref = "HEAD",
    sha = NULL,
    auth_token = Sys.getenv("GITHUB_PAT")
  )
  remote_obj <- structure(remote_obj, format = format, class = c("github_remote", "remote"))

  remote_sha <- remotes::remote_sha(remote_obj)
  local_sha <- utils::packageDescription(repo, lib.loc = .libPaths())
  if(!"GithubSHA1" %in% names(local_sha)){
    cat(paste0("\033[0;", 33, "m", paste0(repo, "is not installed from github. Probably using build in Rstudio or similar"), "\033[0m", "\n"))
    
  } else {
  
  if (remote_sha != local_sha["GithubSHA1"]) {
    cat(paste0("\033[0;", 31, "m", paste0("NOTE: there is a new version of ", repo, " available"), "\033[0m", "\n"))
  } else {
    cat(paste0("\033[0;", 32, "m", paste0("you have the latest version of ", repo), "\033[0m", "\n"))
  }
  }
}


check_github_sha(username = "username", repo = "repo")


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接