The files you need are often scattered across multiple GitHub organizations and repositories. How can you easily find and access them from R?

The ghr (GitHub-R) package helps you to explore and access GitHub directories from R, using a familiar syntax and interface.

Example

Details

Use ghr_get() to get a GitHub-API response. Notice that the call is memoised.

Use ghr_show_fields() to see what fields are available for a given path.

Use ghr_pull() to access specific fields of the GitHub response.

Use ghr_ls(), ghr_ls_download_url() and ghr_ls_htrml_url() are shortcuts for ghr_pull(ghr_get(path), field = "<field>"). They offer an interface similar to fs::dir_ls().

ghr_ls_download_url() and ghr_ls_htrml_url() are most useful in combination with purrr::map(), utils::browseURL() and reader functions such as read.csv().

You can pass additional arguments to gh::gh() via ..., for example, if you need more items than fit in the default .limit per page.

You can request information from a specific branch via the argument ref or with a path structured like this: owner/repo/subdir@branch


Acknowledgments

Thanks to Gábor Csárdi et. al for the gh package and to Francois Michonneau, James Balamuta, Noam Ross and Bryce Mecum for sharing their ideas and code.