RMI / RMI/resources

Alex's R function to grab envvars and R options

Open
#264 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.