knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

confx

Lifecycle: experimental CRAN status

Extends the scope of {config} by offering path-like retrieval, queries for unnamed config entities and referencing of entities. Config file content can be cached in-memory and can then either be retrieved from cache or from file as desired.

Installation

Development version from GitHub with:

remotes::install_github("rappster/confx")

Usage

TL;DR

Suppose you have a config file config.yml in your package's root directory, you either call

conf_get("path/to/named/entity")

or

conf_get("path/to/unnamed/entity/with/query/<query>")

depending on what type of config entity you want to retrieve (named vs. unnamed entity)

For more detailed explanation of the package continue reading

Demo preliminaries

library(confx)

The package ships with a demo YAML config file:

(path_to_config <- fs::path_package("confx", "configs/config.yml"))

You can use this file by setting the following environment variable:

Sys.setenv(R_CONFIG_DIR = fs::path_package("confx", "configs"))

Get named entities

Entire config content:

conf_get()

Entity host:

conf_get("host")

Entity host but from different config environment:

conf_get("host", config = "prod")

Entity host/server_001:

conf_get("host/server_001")

Entity host/server_001/url

conf_get("host/server_001/url")

Get unnamed entities

For unnamed entities (which parse into unnamed lists), you can specify a query consisting of a standard R expression written out as a string:

conf_get("settings_versions/id == 'v1'")
conf_get("settings_versions/valid_from >= '2020-03-01'")
conf_get("settings_versions/
  valid_from >= '2020-03-01' & 
  valid_until >= '2020-10-01'")

DISCLAIMER

When I said standard R expressions, this does not yet reflect the full picture as I started with simple expressions as defined in valid_operators_logical()

confx:::valid_operators_logical()

In future releases, you will also (hopefully) be able to write something like this:

conf_get("settings_versions/
  stringr::str_detect(content, 'HELLO')")

Entity references

TODO



rappster/confx documentation built on March 27, 2021, 2:52 a.m.