## Install usethis package ----
install.packages("usethis")
## Open ~/.Renviron file ----
::edit_r_environ()
usethis# • Modify '~/.Renviron'
# • Restart R for changes to take effect
GitHub 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 ----
::edit_r_profile()
usethis# • Modify '~/.Rprofile'
# • Restart R for changes to take effect
In the ~/.Rprofile
file, add this new line: options(usethis.protocol = "ssh")
. Do not forget to restart RStudio Desktop.
The
.Renviron
file 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
.Rprofile
file 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.