Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the API key setting user-friendlier #51

Closed
maelle opened this issue Feb 22, 2018 · 13 comments
Closed

make the API key setting user-friendlier #51

maelle opened this issue Feb 22, 2018 · 13 comments
Assignees
Milestone

Comments

@maelle
Copy link
Member

maelle commented Feb 22, 2018

mostly stealing all ideas from https://github.com/hrbrmstr/omdbapi/blob/3b69849a540c844a09cf03fb4005b1fd16f80eb2/R/omdb_api_key.R

@maelle maelle self-assigned this Feb 22, 2018
@dpprdan
Copy link
Member

dpprdan commented Mar 3, 2018

This sets the API key only for the current session, or am I missing something?

@maelle
Copy link
Member Author

maelle commented Mar 4, 2018

No since it uses Sys.setenv?

@dpprdan
Copy link
Member

dpprdan commented Mar 4, 2018

Yeah that's what I thought. For some reason I had the impression that this would set the key permanently when I glanced at it the first time. Don't really know why, though.
To paraphrase you: In the vignette documenting this we can show code example and mention usethis::edit_r_environ() as a way to easily find where the .Renviron is/open it. And link to Efficient R Programming.

@maelle
Copy link
Member Author

maelle commented Mar 4, 2018

I'm still torn between documenting it or making it even easier 😂

@maelle maelle added this to the Version 0.3.0 milestone Mar 23, 2018
@dpprdan
Copy link
Member

dpprdan commented Oct 5, 2018

Just leaving this here as a note: One possible solution would be to Sys.setenv(OPENCAGE_KEY) with oc_configure per session. Also for folks using e.g. the keyring pkg instead of .Renviron.

@maelle
Copy link
Member Author

maelle commented Oct 6, 2018

So your first idea would mean restarting once per session?

For further ref link to keyring https://github.com/r-lib/keyring

@dpprdan
Copy link
Member

dpprdan commented Oct 7, 2018

I meant something like this:

oc_configure <-
  function(
    key = NULL,
    max_rate_per_sec =
      getOption("oc_max_rate_per_sec", default = 1L),
    ...
  ) {
    if (!is.null(key)) {
      Sys.setenv("OPENCAGE_KEY" = key)
    }
    ratelimitr::UPDATE_RATE(
      oc_get_limited,
      ratelimitr::rate(n = max_rate_per_sec, period = 1L)
    )
  }

Probably needs a message() (or check + force argument) in case "OPENCAGE_KEY" is already set in .Renviron.

I like Bob's take on omdb_api_key(). One function setting and getting a value at the same time makes me a bit uneasy, but for this use-case it's quite elegant. However, AFAIK his solution does not support the use case where you would want to permanently store your key with e.g. keyring (or secret, which seems the way to go for company accounts) and not in .Renviron. With the above, one could do this at the beginning of the session/script:

oc_configure(key = keyring::key_get("opencage"))

instead of providing the key with every call like this:

oc_forward("something,something", key = keyring::key_get("opencage")) 

@maelle
Copy link
Member Author

maelle commented Oct 7, 2018

Or we could more simply message about usethis::edit_r_environ() and other possible solutions 🤔

@dpprdan
Copy link
Member

dpprdan commented Oct 7, 2018

You seem to be torn, indeed. 😉

@maelle maelle mentioned this issue Oct 22, 2019
@dpprdan
Copy link
Member

dpprdan commented Oct 22, 2019

FWIW, openrouteservice-r is (planning on) moving away from keyring to .Renviron: GIScience/openrouteservice-r#34

@maelle
Copy link
Member Author

maelle commented Oct 23, 2019

Ah that's interesting! But I thought that keyring also supported .Renviron, I'd need to look into its settings a bit more.

@dpprdan
Copy link
Member

dpprdan commented Jan 29, 2020

@maelle is this is closed by #99?

@maelle
Copy link
Member Author

maelle commented Jan 30, 2020

Yep, indeed!

@maelle maelle closed this as completed Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants