If you install packages from private repos often, passing your authorization token to install_github() becomes tedious. You can avoid that pain very easily. Here is how.

Most of what you need to know is in ?devtools::install_github() (or ?remotes::install_github()):

# To install from a private repo, use auth_token with a token
# from https://github.com/settings/tokens. You only need the
# repo scope. Best practice is to save your PAT in env var called
# GITHUB_PAT.
install_github("hadley/private", auth_token = "abc")

However, that information is so compact that it is difficult to understand – let’s brake it down in two main steps:

Step 1: Get the your authorization token

  1. Go to https://github.com/settings/tokens and create a new token.

  2. Click the box that says “repo”. Here is a screenshot:

(…)

  1. Copy your token; it is a long string, say, abc – but much longer.

Step 2: Store your authorization token

  1. Open your .Rprofile with:
usethis::edit_r_profile()
  1. Add this line (then save, and close):
# Set environmental variable GITHUB_PAT
Sys.setenv(GITHUB_PAT = "abc")

Done! You no longer need to use the argument auth_token because it defaults to the environment variable GITHUB_PAT. Next time you can directly install with:

install_github("hadley/private")