r - 如何使用 R 从 Github 下载整个存储库?

标签 r github download repository

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

最佳答案

概述

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

  1. GitHub repository of interest 上的克隆或下载按钮复制 .zip URL。请务必复制 Download ZIP 中的链接地址,而不是 HTTPS URL。

注意:此步骤假设您对感兴趣的 GitHub 存储库的 main 分支感兴趣。如果不是这种情况,则为 be sure to navigate to the branch you are interested in downloading 。请注意,main 现在是 GitHub 存储库主分支的默认名称。如需更多上下文,请输入 read this article by Alexis Moody hosted on DEVthis article by GitHub

enter image description here

  • 将 .zip URL 粘贴到 download.file()url 参数中以下载感兴趣的 .zip 文件。由于这是一个 GitHub 存储库,因此为 destfile 参数分配与感兴趣的存储库相同的名称会很有帮助(在本例中为 destfile = "meetingsR-master") 。 destfile 参数名称的“-master”部分来自声明您希望下载的感兴趣存储库的分支名称。

    • 注意:请参阅第一步中的注释,了解为什么您可能需要将“master”替换为术语“main”
  • 使用 unzip() 解压下载的 .zip 文件。

  • 可重现的示例

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

    # 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 - 如何使用 R 从 Github 下载整个存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48612676/

    相关文章:

    r - 使用 R Lubridate 提取会计年度

    R:有什么方法可以让我在 Windows 中自动更新我的 R 吗?

    git - 为什么 `git clone` 不克隆所有分支?

    GitHub 自述文件图像损坏 - "violates the following Content Security Policy directive: "img-src 'self'“

    javascript - 在 Chrome 中运行时如何使用 Cypress 测试文件下载

    java - 检查 Java 中的完整文件下载

    r - R中的向量列表-提取向量的一个元素

    Rmarkdown beamer 目录幻灯片,加上非当前部分的灰色

    command-line - 如何使用命令行从私有(private)仓库下载 GitHub Release

    android - 重命名从 webview android 下载