gh_text_files: Read in text files from a GitHub repository

gh_text_filesR Documentation

Read in text files from a GitHub repository

Description

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().

Usage

gh_text_files(owner, name, path = ".", rev = "HEAD", recurse = FALSE)

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.

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.

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.

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()

# you have to opt-in into directory recursion
yay::gh_text_files(owner = "salim-b",
                   name = "pal",
                   path = "tests",
                   recurse = TRUE) |>
  str()

salim-b/yay documentation built on May 17, 2024, 5:24 a.m.