Title: | Simplify Connections to Database Sources |
---|---|
Description: | Connecting to databases requires boilerplate code to specify connection parameters and to set up sessions properly with the DBMS. This package provides a simple tool to fill two purposes: abstracting connection details, including secret credentials, out of your source code and managing configuration for frequently-used database connections in a persistent and flexible way, while minimizing requirements on the runtime environment. |
Authors: | Charles Bailey [aut, cre], Hanieh Razzaghi [aut] |
Maintainer: | Charles Bailey <[email protected]> |
License: | Artistic-2.0 |
Version: | 1.1.1 |
Built: | 2025-02-07 03:11:25 UTC |
Source: | https://github.com/baileych/srcr |
Given vectors of directories, basenames, and suffices, combine them to find existing files.
find_config_files( basenames = .basename.defaults(), dirs = .dir.defaults(), suffices = .suffix.defaults() )
find_config_files( basenames = .basename.defaults(), dirs = .dir.defaults(), suffices = .suffix.defaults() )
basenames |
A vector of file names (without directory or file type) 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. |
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:
the user's $HOME
directory
the directory named .srcr
(no leading .
on Windows) under $HOME
the directory in which the executing script is located
the directory in which the calling function's calling function's
source file is located (typically an application-level library). For
example, if the function my_setup()
calls srcr()
, which in turn calls
find_config_files()
, then the directory of the file containing
my_setup()
will be tried.
the directory in which the calling function's source file is located
(typically a utility function, such as srcr()
)
Note that the current working directory is not part of the search by default. This is done to limit the potential for accidentally introducing (potentially harmful) configuration files by setting the working directory.
In each location, the file names given in basenames
are checked; if
none are specified, several default file names are tried:
the name of the calling function's source file
the name of the executing script
the directory in which the calling function's calling function's
source file is located (typically an application-level library). For
example, if the function my_setup()
calls srcr()
, which in turn calls
find_config_files()
, then the name of the file containing
my_setup()
will be tried.
The suffices (file "type"s) of .json
, .conf
, and nothing,
are tried with each candidate path; you may override this default by
using the suffices
parameter. Finally, in order to accommodate the Unix
tradition of "hidden" configuration files, each basename is prefixed with
a period before trying the basename alone.
A vector of path specifications, or an empty vector if none are found.
## Not run: 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')) ## End(Not run)
## Not run: 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')) ## End(Not run)