
Save the API token in the .Renviron
file for repeated use
Source: R/api_connection.R
store_unifi_api_token.Rd
This function will add the UNIFI API token to your .Renviron
file so it can be called securely without being stored
in your code. After you have installed your key, it can be called any time by typing Sys.getenv("UNIFI_API_TOKEN")
and can be
used in package functions by simply typing UNIFI_API_TOKEN
If you do not have an .Renviron
file, the function will create on for you.
If you already have an .Renviron
file, the function will append the key to your existing file, while making a backup of your
original file for disaster recovery purposes.
Function obtained and adapted from the tidycensus package
Arguments
- token
The API token retrieved from UNIFI formated in quotes.
- overwrite
If this is set to TRUE, it will overwrite an existing UNIFI_API_TOKEN that you already have in your
.Renviron
file.- install
if TRUE, will install the token in your
.Renviron
file for use in future sessions. Defaults to FALSE.- verbose
Adding information messages if TRUE
Examples
if (FALSE) { # \dontrun{
unifi_api_token("111111abc", install = TRUE)
# First time, reload your environment so you can use the key without restarting R.
readRenviron("~/.Renviron")
# You can check it with:
Sys.getenv("UNIFI_API_TOKEN")
} # }
if (FALSE) { # \dontrun{
# If you need to overwrite an existing key:
unifi_api_token("111111abc", overwrite = TRUE, install = TRUE)
# First time, relead your environment so you can use the key without restarting R.
readRenviron("~/.Renviron")
# You can check it with:
Sys.getenv("UNIFI_API_TOKEN")
} # }