Skip to contents

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

Usage

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

Arguments

path

Path to a directory, relative to the repository root. A character scalar.

owner

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

name

Repository name. 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.

Value

A character scalar, or an empty character vector in case no text file is found under rev:path.

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

Examples

yay::gh_text_file(path = "pal.Rproj",
                  owner = "salim-b",
                  name = "pal",
                  rev = "HEAD~2") |>
  cat()
#> Version: 1.0
#> 
#> RestoreWorkspace: No
#> SaveWorkspace: No
#> AlwaysSaveHistory: Default
#> 
#> EnableCodeIndexing: Yes
#> UseSpacesForTab: Yes
#> NumSpacesForTab: 2
#> Encoding: UTF-8
#> 
#> RnwWeave: Sweave
#> LaTeX: pdfLaTeX
#> 
#> AutoAppendNewline: Yes
#> StripTrailingWhitespace: Yes
#> LineEndingConversion: Posix
#> 
#> BuildType: Package
#> PackageUseDevtools: Yes
#> PackageInstallArgs: --no-multiarch --with-keep.source
#> PackageRoxygenize: rd,collate,namespace
#> 
#> QuitChildProcessesOnExit: Yes
#> 
#> MarkdownWrap: Column
#> MarkdownWrapAtColumn: 160
#> MarkdownReferences: Section
#> MarkdownCanonical: Yes