Downloads the text file under the specified path from a GitHub repository via GitHub's GraphQL API and returns its content as a string.
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.
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_release_latest()
,
gh_releases()
,
gh_text_files()
Examples
yay::gh_text_file(owner = "salim-b",
name = "pal",
path = "pal.Rproj",
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