data_dir returns the absolute, normalized path to the data directory of a program/package/app based on an optional app-specific commandline argument, an optional app-specific environment variable and the XDG Base Directory Specification
Usage
data_dir(
app_name,
cl_arg = commandArgs()[grep("--data-dir", commandArgs()) + 1],
env_var = Sys.getenv(toupper(paste0(app_name, "_DATA_DIR"))),
create = FALSE,
sep = "/"
)Details
The following algorithm is used to determine the location of the data directory for application $app_name:
If parameter
$cl_argis a non-empty string, returncl_argElse, if parameter
$env_varis a non-empty string, return$env_varElse, if environment variable (EV)
$XDG_DATA_HOMEexists, return$XDG_DATA_HOME/$app_nameElse, if EV
$HOMEexists, return$HOME/.local/share/$app_nameElse, if EV
$USERPROFILEexists, return$USERPROFILE/.local/share/$app_nameElse, return
$WD/.local/share