1

I received a token to access the IUCN redlist portal in R through an API. From InsideR, I read the following:

"iucn_summary uses the new Redlist API for searching for a IUCN ID, so we use the rl_search function internally. This function requires an API key. Get the key at http://apiv3.iucnredlist.org/api/v3/token, and pass it to the key parameter, or store in your .Renviron file like IUCN_REDLIST_KEY=yourkey or in your .Rprofile file like options(iucn_redlist_key="yourkey"). We strongly encourage you to not pass the key in the function call but rather store it in one of those two files. This key will also set you up to use the rredlist package."

How do I store my key in the .Rprofile?

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Niels Raes
  • 51
  • 1
  • 7
  • These instructions are about as precise as you can get. Either edit your .Renviron or .Rprofle files with the code as given in your question. Can you be more specific where exactly you get stuck? – Andrie Jun 08 '16 at 11:16
  • [Here's what R does on startup](https://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html). Read that to figure out where your `.Renviron` file is (I have no idea what OS you are using). Then add a line to the `.Renviron` that goes something like: `IUCN_REDLIST_KEY=yourkey`. Restart R (if open) and it'll be in the environment. – hrbrmstr Jun 08 '16 at 11:26
  • I was unable to find .Renviron but found .Rprofile here: C:\Program Files\R\R-3.3.0\etc on my Windows PC. I added the line options(iucn_redlist_key="yourkey"). – Niels Raes Jun 09 '16 at 13:07

2 Answers2

2

From R run file.edit("~/.Rprofile") or file.edit("~/.Renviron") which will open the file. Enter your values as follows:

VAR1 = apikey1

VAR2 = apikey2

In Linux systems file.edit() opens vim, once you're finished, escape the insert mode with : and enter :x to save the edits

More on the topic:

https://cran.r-project.org/web/packages/httr/vignettes/secrets.html

Mesozoik
  • 109
  • 4
0

snippet tii 
  setDefaults(getSymbols.${1:tiingo},env=.GlobalEnv,api.key="COPY AND PASTE YOUR OWN KEY HERE")

This is probably the most easiest way for you!

not make it complicated, neither .Rproject file nor other modifying initial seetings. Go directly to create a Snippet that includes your infomation.

My primary motivation is to store my api key of getSymbols.tiingo function in quantmod, the key is a string of characters and numbers, I don't want to log in to tiingo website to enquire my key every time I open Rstudio. Simple wish, isn't it?

Here is what I did.

tool > global option> code> edit snippet. then create a snippet as you wish.

save this snippet and give it a try. In my case, i just type tii in my Console, and then Shift+Tab to lock in my snippet, then ENTER, all done!