find_config_files: Locate candidate configuration files

Description Usage Arguments Details Value Examples

View source: R/src_argos.R

Description

Given vectors of directories, basenames, and suffices, find_config_files combines them to find existing files.

Usage

1
2
find_config_files(basenames = .basename.defaults(), dirs = .dir.defaults(),
  suffices = .suffix.defaults())

Arguments

basenames

A vector of file names to use in searching for configuration files.

dirs

A vector of directory names to use in searching for configuration files.

suffices

A vector of suffices (file "type"s) to use in searching for the configuration file.

Details

This function is intended to support a variety of installation patterns, so it attempts to be flexible in looking for configuration files. First, environment variables of the form basename_CONFIG, where <basename> is the uppercase form of each candidate basename, are examined to see whether any translate to a file path.

Following this, the path name parts supplied as arguments are used to build potential file names. If dirs is not specified, the following directories are checked by default:

  1. the user's $HOME directory

  2. the directory in which the executing script is located

  3. the directory in which the calling function's calling function's source file is located (typically an application-level library)

  4. the directory in which the calling function's source file is located (typically a utility function, such as src_argos)

. In each location, the file names given in basenames are checked; if not specified, several default file names are tried:

  1. the name of the calling function's source file

  2. the name of the executing script

  3. the directory in which the calling function's calling function's source file is located (typically an application-level library)

. The suffices (file "type"s) of .json, .conf, and nothing, are tried with each candidate path; you may override this default by specifying suffices. Finally, in order to accommodate the Unix tradition of "hidden" configuration files, each basename is prefixed with . before tryng the basename alone.

Value

A vector of path specifications

Examples

1
2
3
4
5
find_config_files() # All defaults
find_config_files(dirs = c(file.path(Sys.getenv('HOME'),'etc'),
                          '/usr/local/etc', '/etc'),
                 basenames = c('my_app'),
                 suffices = c('.conf', '.rc'))

baileych/ohdsi-argos documentation built on Dec. 1, 2019, 12:41 p.m.