load_dot_env: Load environment variables from the specified file

Description Usage Arguments Details Examples

View source: R/dotenv-package.r

Description

Load variables defined in the given file, as environment variables.

Usage

1
load_dot_env(file = ".env")

Arguments

file

The name of the file to use.

Details

The file is parsed line by line, and line is expected to have one of the following formats:

1
2
3
4
5
6
VARIABLE=value
VARIABLE2="quoted value"
VARIABLE3='another quoted variable'
# Comment line
export EXPORTED="exported variable"
export EXPORTED2=another

In more details:

It is suggested to keep the file in a form that is parsed the same way with dotenv and bash (or other shells).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Remove, if it exists
Sys.unsetenv("dotenvexamplefoo")
Sys.getenv("dotenvexamplefoo")

# Load from a file
tmp <- tempfile()
cat("dotenvexamplefoo=bar\n", file = tmp)
load_dot_env(tmp)
Sys.getenv("dotenvexamplefoo")

# Clean up
unlink(tmp)

Example output

[1] ""
[1] "bar"

dotenv documentation built on April 22, 2021, 5:08 p.m.