## Install usethis package ----
install.packages("usethis")
## Open ~/.Renviron file ----
usethis::edit_r_environ()
# • Modify '~/.Renviron'
# • Restart R for changes to take effectGitHub Personal Access Token
If you want to use the GitHub API, essentially with the packages usethis and rcompendium, you need to create a GitHub Personal Access Token (PAT).
Proceed as follow:
- Go to https://github.com/settings/tokens
- Click on Generate new token (classic)
- Choose a name for your new token (e.g. your laptop name)
- Select no expiration date
- In the section Select scopes, select at least repo and workflow
- Copy this token
Then open RStudio Desktop and run:
The last command will open the ~/.Renviron file. Add this new line: GITHUB_PAT='ghp_XXX' where ghp_XXX is your token. Do not forget to restart RStudio Desktop.
Finally let’s tell usethis to use the SSH protocol to communicate with GitHub. Open RStudio and run:
## Open ~/.Rprofile file ----
usethis::edit_r_profile()
# • Modify '~/.Rprofile'
# • Restart R for changes to take effectIn the ~/.Rprofile file, add this new line: options(usethis.protocol = "ssh"). Do not forget to restart RStudio Desktop.
The
.Renvironfile is a good place to store secrets (API tokens, password, etc.). This file is read by at startup. To access these variables, you can use the functionSys.getenv("GITHUB_PAT").The
.Rprofilefile allows you to run command lines at startup. You can customize the default behaviour of and define some variables withoptions(). To access these variables, you can useoptions()$"usethis.protocol".
More information here.