Reads a .env file with gptr's own parser (a UTF-8 byte-order mark, CRLF line ends,
export prefixes, single and double quotes, multi-line quoted values, # comments and
hyphenated names such as jev-key are understood), maps aliases onto canonical variable
names (jev-key, JEV_KEY, JEV_API_KEY and TYPESAFE_KEY become TYPESAFE_API_KEY; a
line spelled exactly as the canonical name wins over an alias), registers secret values
in gptr's vault for redaction, and exports the canonical names with Sys.setenv(). Plain
configuration fields with suffixes such as _URL or _PATH are not registered as
secrets. It never prints, logs or returns a value.
Usage
gptr_env(
path = ".env",
aliases = NULL,
set_env = getOption("gptr.env_export", TRUE),
override = FALSE,
quiet = FALSE
)Arguments
- path
Path of an existing
.envfile.- aliases
NULL, or a named list of extra aliases,canonical = c("alias", ...), added to the built-in table and to the registeredenv_aliasspecs.- set_env
If
TRUE, export the canonical names to the environment of this R process; ifFALSE, keep the values in the vault only. Defaults togetOption("gptr.env_export", TRUE).- override
If
TRUE, overwrite variables that are already set.- quiet
If
TRUE, do not report what was loaded.
Value
Invisibly, a gptr_env_report data frame with columns name (as spelled in the
file), variable (the canonical name), secret, fingerprint and action ("set",
"registered", "skipped" or "duplicate"), and the attribute bad_lines (the numbers
of malformed lines). It holds names and fingerprints, never values.
Examples
f = tempfile(fileext = ".env")
writeLines("jev-key=example-not-a-real-key-123", f)
gptr_env(f, set_env = FALSE)$variable
#> Loaded 1 variable(s) from file200864738187.env: TYPESAFE_API_KEY #97c871 (from jev-key) [registered]
#> [1] "TYPESAFE_API_KEY"
unlink(f)