Alex's R function to grab envvars and R options
Open
Nobody has claimed this yet.
best-practice
r-stats
- Dominant language
- No language data
- Stars
- 17
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
A function I’ve written to grab useful values from either envvars or R options, to allow some flexibility in how we access those -- @AlexAxthelm
#' @export
get_database_user <- function(
envvar = "POSTGRES_USER",
option = "database_user"
) {
if (Sys.getenv(envvar) != "") {
return(Sys.getenv(envvar))
} else if (!is.null(options(option)[[option]])) {
return(options(option)[[option]])
} else if (require("rstudioapi") & rstudioapi::isAvailable()) {
return(rstudioapi::askForPassword("Database User"))
} else {
stop("Please add database user as envvar or R option")
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating where the R package or scripts define database configuration and where get_database_user would be used. Clarify whether this proposed function should be added and which environment variable, R option, RStudio prompt, and error behavior are required. Done means the agreed behavior is implemented and covered by the repository's existing checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100