1

I am writing an R-notebook that uses an API to fetch data, e.g. Quandl.

For my API function calls to work I must first set my API key. I want to share the notebook code with other developers on my team, but I do not want them to have access to my API key.

For example, my code looks like:

Quandl.api_key('MY_SECRET_API_KEY')    # set the API key for Quandl library    
my_data<- Quandl("USTREASURY/YIELD")   # Make some function calls

How do I run the first line with my secret value without saving it in the R Notebook?

FistOfFury
  • 6,735
  • 7
  • 49
  • 57
  • 1
    Simplest option (still not fully secure), save the key in a text file in your working directory. Then `my_key = readLines("my_api.txt"); Quandl.api_key(my_key)`. Make sure any version control systems ignore the text file. – Gregor Thomas Dec 10 '18 at 18:38
  • 2
    For more info and options, see [Managing secrets in R](https://cran.r-project.org/web/packages/httr/vignettes/secrets.html), a `httr` vignette.. – Gregor Thomas Dec 10 '18 at 18:39
  • @Gregor thanks for your suggestions. reading for the local file directory should work. – FistOfFury Dec 10 '18 at 19:35

0 Answers0