tidyverse/design

Use options or env vars for user set-able defaults

Opened this issue · 2 comments

from @jimhester about env vars vs. options:


benefits:

  1. Easier to set in CIs and for server administrators who may not know R
  2. Automatically propagates to child processes
  3. Users familiar with other languages already understand them

drawbacks:

  1. Just strings, so you have to coerce them appropriately
  2. Can't really have more complicated values
  3. Maybe more cumbersome to understand for R-only users
  4. Potentially easier to expose sensitive information (e.g. RStudio dumping all envvars to a file as happened previously)

Open questions:

  • Should env vars us an R_ prefix? (vroom vs. remotes)
  • Should you also use an option?
  • When should you write a helper?

We discussed this again today in slack and covered a lot of the same ground as above. But I think this from @gaborcsardi is still worth adding here.


Some facts and opinions:

  • Env vars are not great for setting complex values, e.g. you would not want to tell the user to set an env var to an R function, or a deep list. Env vars are best for single strings, flags or scalar numbers. They are ok for a list of strings or numbers.
  • Env vars are inherited by subprocesses.
  • Env vars are easier to set by admins.
  • Env vars can be set by an admin in a way that no R process will ignore them.
  • Options are not inherited by subprocesses.
  • Options are harder to set by admins.
  • It is not (easily) possible to set options for all R processes, by admins. (E.g. --vanilla will ignore .Rprofile.)
  • It is best to support both env vars and options for a configuration value, unless it has a complex value.
  • If you support both env vars and options, options should take precedence.
  • There is no consensus wrt what to do if the env var or option is set to a nonsensical value. IMO you should error.
  • It is nice to have a manual page that lists all env vars and options, supported by a package. E.g. https://cli.r-lib.org/reference/cli-config.html