如何使用R从Github下载整个存储库? [英] How to download entire repository from Github using R?

查看:51
本文介绍了如何使用R从Github下载整个存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用R从Github下载整个存储库?我要访问的这些文件不是.csv文件(大多数教程都讲授).它们是.r和.rmd文件的混合,我想分别或一次读入R.谢谢:)

解决方案

概述

您可以通过三个步骤使用R从GitHub下载整个存储库:

  1. Clone或下载按钮上的

    1. 将.zip URL粘贴到).主" destfile 参数名称的一部分来自声明您要下载的目标存储库的分支名称.

    2. 使用 unzip() 解压缩下载的.zip文件.

    可复制示例

    使用下面的代码时,请注意更改文件路径.

     #设置工作目录,因此我知道.zip文件的位置setwd(dir ="/some/path/")#下载存储库的.zip文件#从克隆或下载-下载ZIP"按钮#在感兴趣的GitHub存储库上download.file(url =" https://github.com/jumpingrivers/meetingsR/archive/master.zip",destfile ="meetingsR-master.zip")#解压缩.zip文件解压缩(zipfile ="meetingsR-master.zip")#设置工作目录#位于新解压缩的内部#感兴趣的GitHub存储库setwd(dir ="/some/path/meetingsR-master/")#检查内容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";#脚本结尾# 

    Is it possible to download an entire repository from Github using R? These files I want to access are NOT .csv files (which most tutorials teach). They are a mix of .r and .rmd files, which I want to read into R either separately or all at once. Thanks :)

    解决方案

    Overview

    You can download an entire repository from GitHub using R in three steps:

    1. Copy the .zip URL from the Clone or download button on the GitHub repository of interest. Be sure to copy the link address from Download ZIP and not the HTTPS URL.

    Note: This step assumes you are interested in the main branch of the GitHub repository of interest. If this is not the case, be sure to navigate to the branch you are interested in downloading. Please note that main is now the default name of the main branch of a GitHub repository. For more context, please read this article by Alexis Moody hosted on DEV and this article by GitHub.

    1. Paste the .zip URL into the url parameter of download.file() to download the .zip file of interest. Since this is a GitHub repository, it is helpful to assign the destfile parameter the same name as the repository of interest (in this case, destfile = "meetingsR-master"). The "-master" portion of the destfile parameter name comes from declaring the branch name of the repository of interest that you wish to download.

      • Note: please see note in step one to understand why you might need to replace "master" with the term "main".
    2. Use unzip() to unzip the downloaded .zip file.

    Reproducible Example

    Be mindful to change the file paths when using the code down below.

    # 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 #
    

    这篇关于如何使用R从Github下载整个存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆