https://github.com/tanaylab/tgconfig
The goal of tgconfig is to provide infrastructure for managing package parameters, (inspired by https://github.com/r-lib/pkgconfig)
https://github.com/tanaylab/tgconfig
Last synced: 5 months ago
JSON representation
The goal of tgconfig is to provide infrastructure for managing package parameters, (inspired by https://github.com/r-lib/pkgconfig)
- Host: GitHub
- URL: https://github.com/tanaylab/tgconfig
- Owner: tanaylab
- License: gpl-3.0
- Created: 2019-08-25T09:42:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-04T19:35:05.000Z (over 5 years ago)
- Last Synced: 2024-08-13T07:13:32.031Z (8 months ago)
- Language: R
- Homepage: https://tanaylab.github.io/tgconfig
- Size: 79.1 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - tanaylab/tgconfig - The goal of tgconfig is to provide infrastructure for managing package parameters, (inspired by https://github.com/r-lib/pkgconfig) (R)
README
---
output:
md_document:
variant: markdown_github
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-",
error = TRUE
)
```[](https://travis-ci.org/tanaylab/tgconfig)
[](https://codecov.io/gh/tanaylab/tgconfig?branch=master)# tgconfig
The goal of tgconfig is to provide infrastructure for managing package parameters, inspired by [pgkconfig](https://github.com/r-lib/pkgconfig)
## Code
code can be found at https://github.com/tanaylab/tgconfig
## Installation
```{r, eval=FALSE}
install.packages('tgconfig', repos=c(getOption('repos'), 'https://tanaylab.github.io/repo'))
```## Usage
Parameters are easy to get in relevant functions within a package:
```{r example}
library(tgconfig)
register_param('param', 'scrdb')
set_param('param', 'value', 'scrdb')
get_param_strict('param', 'scrdb')
```Error is thrown if a parameter is missing:
```{r}
get_param_strict('another', 'scrdb')
```Developers are able to register parameters and set their default value in a config file that is part of the package in YAML format:
```
char_param: value
expr_param: !expr seq(1:5)
numeric_param: 500
boolean_param: true
``````{r}
config_file <- example_config_file()
register_params(config_file, 'scrdb')
get_package_params('scrdb')
```Users are able to override parameters using their own YAML:
```
char_param: 'user_char'
expr_param: 'user_exp'
numeric_param: 700
boolean_param: false
```
```{r}
override_params(system.file('config/override_example.yaml', package='tgconfig'), package='scrdb')
get_package_params('scrdb')
```Users get an exception when trying to override a parameter that was not registered:
```{r}
set_param('other_param', 'value', 'scrdb')
```Users can load multiple parameters to the current environment:
```{r}
load_params_to_env(c('expr_param', 'boolean_param'), 'scrdb')
expr_param
boolean_param
```