Learn R Programming

envvar (version 0.1.2)

envvar_get_file: 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, ... )

Value

A string containing the path to a file or directory

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()

Examples

Run this code
# \donttest{
# 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")
# }
# \donttest{
envvar_set("MY_DATA_DIR" = "data")
envvar_get_dir("MY_DATA_DIR")

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

Run the code above in your browser using DataLab