Use options or env vars for user set-able defaults
Opened this issue · 2 comments
hadley commented
from @jimhester about env vars vs. options:
benefits:
- Easier to set in CIs and for server administrators who may not know R
- Automatically propagates to child processes
- Users familiar with other languages already understand them
drawbacks:
- Just strings, so you have to coerce them appropriately
- Can't really have more complicated values
- Maybe more cumbersome to understand for R-only users
- Potentially easier to expose sensitive information (e.g. RStudio dumping all envvars to a file as happened previously)
hadley commented
Open questions:
- Should env vars us an
R_
prefix? (vroom vs. remotes) - Should you also use an option?
- When should you write a helper?
jennybc commented
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