获取 github 存储库并解压到临时目录中

Tyl*_*ker 0 r unzip

我希望能够获取 github 存储库并将其内容解压缩到临时目录。我知道 devtools 中有 install_github 的功能,但我不想安装,这对于所有 github 存储库来说更通用。

这是我尝试过的:

url <- "https://github.com/trinker/reports/zipball/master"
tmp <- tempfile( fileext = ".zip" )
download.file(url, tmp)
unzip(tmp, exdir = tempdir())  
Run Code Online (Sandbox Code Playgroud)

这导致:

Warning message:
In unzip(tmp, exdir = tempdir()) : internal error in unz code
Run Code Online (Sandbox Code Playgroud)

同样,我不想安装,但可以访问临时目录中的内部文件,退出时我将删除这些文件。

Ram*_*ath 5

使用downloader简化下载界面的包。这是实现您目标的功能。

#' Download and unzip Github repo to current directory
#'
#' @params repo name of github repository
#' @params user github user name
download_repo <- function(repo, user){
  require(downloader)
  url <- sprintf("https://github.com/%s/%s/archive/master.zip", user, repo)
  tmp <- tempfile(fileext = ".zip")
  download(url, tmp)
  unzip(tmp)  
}

# download_repo('reports', 'trinker')
Run Code Online (Sandbox Code Playgroud)