Skip to contents

envvar_get_url() gets a URL value from an environment variable and parses it with httr2::url_parse.

envvar_get_ipaddress() gets an IP address value from an environment variable

Usage

envvar_get_url(x, default = NULL, validate = NULL, warn_default = TRUE)

envvar_get_ipaddress(x, default = NULL, validate = NULL, warn_default = TRUE)

Arguments

x

String containing an environment variable name

default

Optional default value if the environment variable is not set

validate

Optional function that checks a value for validity

warn_default

Show a warning if the default value is used (default: TRUE)

Value

envvar_get_url() returns a URL: an S3 list with class httr2_url and elements scheme, hostname, port, path, fragment, query, username, password, where applicable.

envvar_get_ipaddress() returns an ip_address vector

Examples


# Get a URL value and ensure that it is https
envvar_set("TEST_URL" = "https://google.com:80/?a=1&b=2")
envvar_get_url("TEST_URL", validate = \(x) x$scheme == "https")
#> <httr2_url> https://google.com:80/?a=1&b=2
#>scheme: https
#>hostname: google.com
#>port: 80
#>path: /
#>query:
#>a: 1
#>b: 2

# Get an IP address value and ensure that it is IPv4
envvar_set("TEST_HOST" = "192.168.1.15")
envvar_get_ipaddress("TEST_HOST", validate = ipaddress::is_ipv4)
#> <ip_address[1]>
#> [1] 192.168.1.15