src_argos: Connect to database using config file

Description Usage Arguments Details Value Examples

View source: R/src_argos.R

Description

src_argos sets up a dplyr or DBI data source using information from a JSON configuration file, and returns the data source.

Usage

1
src_argos(basenames = NA, dirs = NA, paths = NA, config = NA)

Arguments

basenames

A vector of file names to use in searching for configuration file, if paths is absent. It defaults to the name of this file.

dirs

A vector of directory names to use in searching for configuration files, if paths is absent. It defaults to $HOME, the location of the file containing the calling function, and the location of this file.

paths

A vector of full path names for the configuration file. If present, only paths is checked.

config

A list containg the configuration data, to be used instead of reading a configuration file, should you wish to skip that step.

Details

The configuration file must provide all of the information necessary to set up the src or DBI connection. Given the variety of ways a data source can be specified, the JSON must be a two-element hash. The src_name key points to a string containing name of a dplyr function that sets up the data source (e.g. src_postgres), or of a DBI driver method (e.g. SQLite), as one might pass to dbDriver. If the src_name begins with src_, it is taken as the former, otherwise it is taken as the latter. In this case, an attempt will be made to load an appropriate DBI library if the driver function is not found.

The src_args key points to a nested hash, whose keys are the arguments to that function, and whose values are the argument values.

If paths is present, only the specified paths are checked. Otherwise, find_config_files is called to locate candidate configuration files, using dirs and basenames, if present. The first file that exists, is readable, and evaluates as legal JSON is used as the source of configuration data.

Value

A src object. The specific class of the object is determined by the src_name in the configuration data.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
# Search all the (filename-based) defaults
src_argos()

# "The usual"
src_argos('myproj_prod')

# Look around
src_argos( dirs = c(Sys.getenv('PROJ_CONF_DIR'), 'var/lib', getwd()),
           basenames = c('myproj', Sys.getenv('PROJ_NAME')) )

# No defaults
src_argos(paths = c('/path/to/known/config.json'))

## End(Not run)

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