如何,使用R从GitHub下载整个仓库?

问题描述 投票:4回答:2

是否有可能,使用R从GitHub下载整个仓库?这些文件我要访问不的.csv文件(其中大部分教程教)。他们是.R和.rmd文件,我想单独或一次全部读成R组合。谢谢 :)

r github download repository rstudio
2个回答
8
投票

Overview

您可以在三个步骤,使用R从GitHub下载整个仓库:

  1. 该.zip URL从上Clone or downloadGitHub repository of interest按钮复制。务必从Download ZIP而不是HTTPS URL复制链接地址。

注:此步骤假定您有兴趣的利益GitHub的库的master分支。如果不是这种情况,be sure to navigate to the branch you are interested in downloading

enter image description here

  1. 该.zip URL粘贴到urldownload.file()参数下载感兴趣的.zip文件。由于这是一个GitHub的仓库,是有帮助的同名分配destfile参数为关注存储库(在这种情况下,destfile = "meetingsR-master")。该destfile参数名的“ - 主”一部分来自宣称的,你想下载感兴趣的资料库的分支名。
  2. 使用unzip()解压下载的zip文件。

Reproducible Example

要留意使用下来下面的代码时,更改文件路径。

# set working directory so I know where the .zip file will be located
setwd(dir = "/some/path/")

# download a .zip file of the repository
# from the "Clone or download - Download ZIP" button
# on the GitHub repository of interest
download.file(url = "https://github.com/jumpingrivers/meetingsR/archive/master.zip"
                                   , destfile = "meetingsR-master.zip")

# unzip the .zip file
unzip(zipfile = "meetingsR-master.zip")

# set the working directory
# to be inside the newly unzipped 
# GitHub repository of interest
setwd(dir = "/some/path/meetingsR-master/")

# examine the contents
list.files()
# [1] "_book"                                
# [2] "_output.yml"                          
# [3] "01-events.Rmd"                        
# [4] "02_useR_groups_aaa.Rmd"               
# [5] "02_useR_groups_asia.Rmd"              
# [6] "02_useR_groups_europe.Rmd"            
# [7] "02_useR_groups_middle_east_africa.Rmd"
# [8] "02_useR_groups_north_america.Rmd"     
# [9] "02_useR_groups_oceania.Rmd"           
# [10] "02_useR_groups_south_america.Rmd"     
# [11] "03-Rladies.Rmd"                       
# [12] "css"                                  
# [13] "deploy.sh"                            
# [14] "DESCRIPTION"                          
# [15] "docs"                                 
# [16] "index.Rmd"                            
# [17] "inverse.png"                          
# [18] "logo.png"                             
# [19] "Makefile"                             
# [20] "NAMESPACE"                            
# [21] "R"                                    
# [22] "README.md"                            
# [23] "Rmeetings.Rproj"

# end of script #

4
投票

我看到这个问题有rstudio标签。您可以使用rstudio(和避免命令行)通过选择文件 - >新项目 - >版本控制 - > Git和在Repository URL字段中输入您想要的Github上库的地址。

你打Create Project按钮后,rstudio将下载资料库的内容,创建一个新的项目,改变你的工作目录到新的项目。

http://happygitwithr.com/rstudio-git-github.html#clone-the-new-github-repository-to-your-computer-via-rstudio


1
投票

您可以通过安装包usethis,使用R从GitHub下载整个仓库:

install.packages( 'usethis')

.git的URL从克隆复制或下载感兴趣的GitHub的库按钮。请务必将链接地址从下载ZIP,而不是HTTPS URL复制。

例如,我想下载这个repository。我会复制从下载ZIP(https://github.com/cwickham/purrr-tutorial.git)的链接地址,并将其粘贴在usethis::use_course()然后取出git的,并与/archive/master.zip更换

usethis use_course( 'https://github.com/cwickham/purrr-tutorial/archive/master.zip')

然后,遵循来自R在哪里保存文件的提示问题。

© www.soinside.com 2019 - 2024. All rights reserved.