Downloads all text files under the specified path from a GitHub repository via GitHub's GraphQL API and returns a named character vector with the file paths as names and the file contents as values.
This is a simple convenience function combining gh_dir_ls()
and gh_text_file()
.
Arguments
- owner
Repository owner's GitHub user or organization name. A character scalar.
- name
Repository name. A character scalar.
- path
Path to a directory, relative to the repository root. A character scalar.
- rev
Git revision expression matching the desired Git tree object, e.g. a branch or tag name or another symbolic reference like
"HEAD@{yesterday}"
or"HEAD~10"
. A character scalar.- recurse
Whether or not to also include text files in subfolders of
path
. Enabling this option may result in many API calls and thus produce a significant delay.
Value
A named character vector of length equal to the number of files found under rev:path
with the file paths as names and the file contents as values.
Details
Works for both public and private repositories, for the latter you just need to set up a sufficiently authorized GitHub Personal Access Token (PAT).
Note that nothing is returned in case of a binary file, as if no file at all existed under the given
path
.
See also
Other GitHub functions:
gh_dir_ls()
,
gh_release_latest()
,
gh_releases()
,
gh_text_file()
Examples
yay::gh_text_files(owner = "salim-b",
name = "pal",
path = "tests") |>
str()
#> Named chr "library(testthat)\nlibrary(pal)\n\ntest_check(\"pal\")\n"
#> - attr(*, "names")= chr "tests/testthat.R"
# you have to opt-in into directory recursion
yay::gh_text_files(owner = "salim-b",
name = "pal",
path = "tests",
recurse = TRUE) |>
str()
#> Named chr [1:11] "library(testthat)\nlibrary(pal)\n\ntest_check(\"pal\")\n" ...
#> - attr(*, "names")= chr [1:11] "tests/testthat.R" "tests/testthat/test-cli.R" "tests/testthat/test-git.R" "tests/testthat/test-internal.R" ...