config_file
returns the absolute, normalized path to the configuration file 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
config_file(
app_name,
file_name,
cl_arg = commandArgs()[grep("--config-file", commandArgs()) + 1],
env_var = "",
sep = "/",
copy_dir = norm_path(xdg_config_home(), app_name),
fallback_path = NULL
)
Normalized path to the configuration file of $app_name
.
Name of the program/package/app
Name of the configuration file
Value of app specific commandline parameter
Value of app specific environment variable
Path separator to be used on Windows
Path to directory where $fallback_path
should be copied to in case it gets used.
Value to return as fallback (see details)
The following algorithm is used to determine the location of $file_name
:
If $cl_arg
is a non-empty string, return it
Else, if $env_var
is a non-empty string, return it
Else, if $PWD/.config/$app_name
exists, return it
Else, if $XDG_CONFIG_HOME/$app_name/$file_name
exists, return it
Else, if $HOME/.config/$app_name/$file_name
exists, return it
Else, if $USERPROFILE/.config/$app_name/$file_name
exists, return it
Else, if $copy_dir
is non-empty string and $fallback_path
is a path
to an existing file, then try to copy $fallback_path
to
copy_dir
/$file_name
and return copy_dir
/$file_name
(Note, that
in case $copy_dir is a non-valid path, the function will throw an error.)
Else, return $fallback_path
config_dir()
, xdg_config_home()