data_dir {toscutil} | R Documentation |
Get Normalized Data Directory Path of a Program
Description
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 = "/"
)
Arguments
app_name |
Name of the program/package/app |
cl_arg |
Value of app specific commandline parameter |
env_var |
Value of app specific environment variable |
create |
whether to create returned path, if it doesn't exists yet |
sep |
Path separator to be used on Windows |
Details
The following algorithm is used to determine the location of the data directory for application $app_name
:
If parameter
$cl_arg
is a non-empty string, returncl_arg
Else, if parameter
$env_var
is a non-empty string, return$env_var
Else, if environment variable (EV)
$XDG_DATA_HOME
exists, return$XDG_DATA_HOME/$app_name
Else, if EV
$HOME
exists, return$HOME/.local/share/$app_name
Else, if EV
$USERPROFILE
exists, return$USERPROFILE/.local/share/$app_name
Else, return
$WD/.local/share
Value
Normalized path to the data directory of $app_name
.
See Also
Examples
data_dir("myApp")