gh_text_file: Read in a text file from a GitHub repository

gh_text_fileR Documentation

Read in a text file from a GitHub repository

Description

Downloads the text file under the specified path from a GitHub repository via GitHub's GraphQL API and returns its content as a string.

Usage

gh_text_file(owner, name, path, rev = "HEAD")

Arguments

owner

Repository owner's GitHub user or organization name. A character scalar.

name

Repository name. A character scalar.

path

Path to a file, 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.

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 character scalar, or an empty character vector in case no text file is found under rev:path.

See Also

Other GitHub functions: gh_dir_ls(), gh_release_latest(), gh_releases(), gh_text_files()

Examples

yay::gh_text_file(owner = "salim-b",
                  name = "pal",
                  path = "pal.Rproj",
                  rev = "HEAD~2") |>
  cat()

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