A personal access token (PAT) is needed for git operations via the GitHub API. Two helper functions are provided:

  • browse_github_token() is synonymous with browse_github_pat(): Both open a browser window to the GitHub form to generate a PAT. See below for advice on how to store this.

  • github_token() retrieves a stored PAT by consulting, in this order:

    • GITHUB_PAT environment variable

    • GITHUB_TOKEN environment variable

    • the empty string ""

browse_github_token(
  scopes = c("repo", "gist", "user:email"),
  description = "R:GITHUB_PAT",
  host = "https://github.com"
)

browse_github_pat(
  scopes = c("repo", "gist", "user:email"),
  description = "R:GITHUB_PAT",
  host = "https://github.com"
)

github_token()

Arguments

scopes

Character vector of token scopes, pre-selected in the web form. Final choices are made in the GitHub form. Read more about GitHub API scopes at https://developer.github.com/apps/building-oauth-apps/scopes-for-oauth-apps/.

description

Short description or nickname for the token. It helps you distinguish various tokens on GitHub.

host

GitHub API host to use. Override with the endpoint-root for your GitHub enterprise instance, for example, "https://github.hostname.com/api/v3".

Value

github_token() returns a string, a GitHub PAT or "".

Get and store a PAT: Sign up for a free GitHub.com account and sign in. Call browse_github_token(). Verify the scopes and click "Generate token". Copy the token right away! A common approach is to store in .Renviron as the GITHUB_PAT environment variable. edit_r_environ() opens this file for editing.

See also

gh::gh_whoami() for information on an existing token.

Examples

if (FALSE) { browse_github_token() ## COPY THE PAT!!! ## almost certainly to be followed by ... edit_r_environ() ## which helps you store the PAT as an env var } # for safety's sake, just reveal first 4 characters substr(github_token(), 1, 4)
#> [1] ""