-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
146 lines (101 loc) · 2.87 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# confx
<!-- badges: start -->
[](https://www.tidyverse.org/lifecycle/#experimental)
[](https://CRAN.R-project.org/package=confx)
<!-- badges: end -->
Extends the scope of [{config}](https://www.github.com/rstudio/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](https://github.com/) with:
```{r, eval=FALSE}
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
```{r, eval=FALSE}
conf_get("path/to/named/entity")
```
or
```{r, eval=FALSE}
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
```{r}
library(confx)
```
The package ships with a demo YAML config file:
```{r}
(path_to_config <- fs::path_package("confx", "configs/config.yml"))
```
You can use this file by setting the following environment variable:
```{r}
Sys.setenv(R_CONFIG_DIR = fs::path_package("confx", "configs"))
```
### Get named entities
Entire config content:
```{r}
conf_get()
```
Entity `host`:
```{r}
conf_get("host")
```
Entity `host` but from different config environment:
```{r}
conf_get("host", config = "prod")
```
Entity `host/server_001`:
```{r}
conf_get("host/server_001")
```
Entity `host/server_001/url`
```{r}
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:
```{r}
conf_get("settings_versions/id == 'v1'")
```
```{r}
conf_get("settings_versions/valid_from >= '2020-03-01'")
```
```{r}
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()`
```{r}
confx:::valid_operators_logical()
```
In future releases, you will also (hopefully) be able to write something like
this:
```{r}
conf_get("settings_versions/
stringr::str_detect(content, 'HELLO')")
```
### Entity references
TODO