dotenv icon indicating copy to clipboard operation
dotenv copied to clipboard

Return the .env output to a list instead of adding to environment

Open dshemetov opened this issue 3 years ago • 1 comments

Would you accept a PR for a function with the functionality of dotenv_values?

Might be as simple as

dotenv_values <- function(file = ".env") {

  if (!file.exists(file)) stop("dot-env file does not exist", call. = TRUE)

  tmp <- readLines(file)
  tmp <- ignore_comments(tmp)
  tmp <- ignore_empty_lines(tmp)

  # If there's no env vars, return nothing
  if (length(tmp) == 0) return(list())

  tmp <- lapply(tmp, parse_dot_line)
  return(tmp)
}

dshemetov avatar Mar 28 '23 00:03 dshemetov

Do you want to submit a PR? Ideally the common parts from the new and the old function would be moved to a new function, and load_dot_env and dotenv_values would both use this new function to avoid code duplication.

gaborcsardi avatar Mar 28 '23 08:03 gaborcsardi