knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
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.
Development version from GitHub with:
remotes::install_github("rappster/confx")
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
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"))
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")
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')")
TODO
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.