The general approach is to set up a permanent token that you will use in R, using the following broad steps:
1. Set up the token in Github.
2. Add the token to your Windows environmental variables.
3. Use the httr
package to send your credentials when accessing the file.
Environment Variables
windowEdit...
in the top half of the window (i.e., the part that has the title "User variables for xyz")Variable name:
box, type GITHUB_TOKENVariable value:
box, paste your PAT (40-character string that you copied from github.com)OK
OK
on the bottom right of the to close the Environment Variables
window.First test that your PAT is working as hoped by typing the following in the R console:
auth <- Sys.getenv("GITHUB_TOKEN")
Make sure that the auth object is your PAT. If not, seek assistance at R office hours or from a colleague.
You can now use the authenticate command in the httr
package to pass your PAT. Here are some examples of how to access code:
get a YAML file config_file <- yaml::yaml.load(httr::GET( url = "https://raw.githubusercontent.com/PHSKC-APDE/bskhs/master/etl/load_raw/load_load_raw.bskhs_2017_phone_web.yaml", httr::authenticate(auth, "")))
run R code eval(parse(text = httr::content(httr::GET( url = "https://raw.githubusercontent.com/PHSKC-APDE/bskhs/master/etl/scripts_general/load_table_bskhs.R", httr::authenticate(auth, "")), "text")))
get a CSV bskhs_2019_names <- vroom::vroom(httr::content(httr::GET( url = "https://raw.githubusercontent.com/PHSKC-APDE/bskhs/master/etl/ref/field_names.csv", httr::authenticate(Sys.getenv("GITHUB_PAT"), "")), type = "text"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.