envvar_get_file {envvar}R Documentation

Environment variables for files and directories

Description

envvar_get_file() gets a file name from an environment variable

envvar_get_dir() gets a directory name from an environment variable

Usage

envvar_get_file(
  x,
  default = NULL,
  create = TRUE,
  check_readable = FALSE,
  check_writable = FALSE,
  transform = NULL,
  warn_default = TRUE,
  ...
)

envvar_get_dir(
  x,
  default = NULL,
  create = TRUE,
  transform = NULL,
  check_readable = FALSE,
  check_writable = FALSE,
  warn_default = TRUE,
  ...
)

Arguments

x

String containing an environment variable name

default

Optional default value if the environment variable is not set

create

Create the file or directory if it does not exist (default: TRUE)

check_readable

Ensure that the file or directory is readable

check_writable

Ensure that the file or directory is writable

transform

Optional function that applies a transformation to the variable's value

warn_default

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

...

Additional arguments passed to fs::file_create for envvar_get_file() or fs::dir_create for envvar_get_dir()

Value

A string containing the path to a file or directory

Examples


# Get a file path and make sure it exists
envvar_set("MY_DATA" = "data.parquet")
envvar_get_file("MY_DATA")

# Cleanup
file.remove("data.parquet")


envvar_set("MY_DATA_DIR" = "data")
envvar_get_dir("MY_DATA_DIR")

# Cleanup
unlink("data", recursive = TRUE)


[Package envvar version 0.1.1 Index]