R 如何从github下载(不安装)软件包

R 如何从github下载(不安装)软件包,r,devtools,R,Devtools,是否从github下载压缩包而不安装 例如,运行: devtools::install_github("tidyverse/tidyr") 立即下载并安装。有什么与之相当的吗 download.packages("tidyr", destdir = "path") 对于github软件包?我认为您可以使用: repo <- "tidyverse/tidyr" download.file( url = paste0("https://api.github.com/repos/", r

是否从github下载压缩包而不安装

例如,运行:

devtools::install_github("tidyverse/tidyr")
立即下载并安装。有什么与之相当的吗

download.packages("tidyr", destdir = "path")
对于github软件包?

我认为您可以使用:

repo <- "tidyverse/tidyr"
download.file(
  url = paste0("https://api.github.com/repos/", repo, "/tarball/master"), 
  destfile = "~/tidyr.tar.gz"
)

这将有效地等同于上述内容。请注意,
remote\u download.github\u remote
功能未导出,因此不是使用它的“官方”方式。

如果要下载github存储库(在本例中为
tidyr
软件包),可以使用
download.file
并通过右键单击复制github“克隆或下载”按钮中的链接

download.file(url = "https://github.com/tidyverse/tidyr/archive/master.zip",
              destfile = "tidyr.zip")
如果您想要一个函数来实现这一点,一个可能的解决方案是(它将在当前工作目录中下载):


这是否需要来自R内部?为什么不直接从github下载repo呢?就像你只需要一个R函数来为你做一个
get clone
?因为回购协议中没有压缩包。这需要建立。或者你想要一个下载和构建但不安装的功能?如果您只是想要压缩包,那么从CRAN而不是github发布官方版本就更容易了。或者您是在特别尝试获取软件包的开发版本吗?github中有一些软件包在cran上不可用。是的,一个下载、构建但不安装的功能正是我想要的。
download.file(url = "https://github.com/tidyverse/tidyr/archive/master.zip",
              destfile = "tidyr.zip")
download_git <- function(repo_name, repo_url, install = FALSE){

   url_git <- paste0(file.path(repo, "archive", "master"), ".zip")
   download.file(url = url_git,
                 destfile = paste0(repo_name, "-master.zip"))

   if(install) {

      unzip(zipfile = paste0(repo_name, "-master.zip"))

      devtools::install(paste0(repo_name,"-master"))    
   }
}
download_git(repo_name = "tidyr", 
             repo_url = "https://github.com/tidyverse/tidyr", 
             install = TRUE)