I'm in the process of writing a blog post that queries an API without an associated R package. Because there's no associated R package, I'm using the httr GET function which requires my API key to be in the string format. My question is, how do I keep my API key private so it doesn't show up in my website's public GitHub repository?
I'm familiar with caching API keys using options( ) as in options(tigris_use_cache = TRUE) for the tidycensus package but not sure how/whether to implement this in rmarkdown/blogdown for the API I linked to above. I haven't been able to find much help from Googling so any insight/tips would be greatly appreciated.
The secret package is good, but I also have been known to make gratuitous use of passwords in environment variables. I pop them in my .Rprofile like this:
I'd also recommend the keyring package, which is used by RStudio 1.2. It's cross-platform and works out of the box with Keychain on macOS and Credential Store on Windows. With an external dependency (libsecret), it also works with Secret Service on Linux. Here's a guide to it from RStudio, but I believe you can also use it independently
I like the simplicity of using a user-hidden config file that your R application accesses. I originally borrowed the idea from a python module genlogics. In my case I was using the same API wrapper for 4 different servers - so I had a configuration file for each one...
~/server-1.config
~/server-2.config
etc. The config and configr make reading/writing config files super easy.