{"id":20626651,"url":"https://github.com/tymekdev/fig","last_synced_at":"2025-04-15T15:20:46.057Z","repository":{"id":56922409,"uuid":"474351172","full_name":"TymekDev/fig","owner":"TymekDev","description":"A Config Package with No \"Con\"","archived":false,"fork":false,"pushed_at":"2023-11-03T11:11:00.000Z","size":75,"stargazers_count":3,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T19:11:45.277Z","etag":null,"topics":["configuration","r-package"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TymekDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-26T13:09:45.000Z","updated_at":"2024-07-07T11:18:08.000Z","dependencies_parsed_at":"2022-08-21T04:50:12.237Z","dependency_job_id":null,"html_url":"https://github.com/TymekDev/fig","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TymekDev%2Ffig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TymekDev%2Ffig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TymekDev%2Ffig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TymekDev%2Ffig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TymekDev","download_url":"https://codeload.github.com/TymekDev/fig/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249094939,"owners_count":21211837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","r-package"],"created_at":"2024-11-16T13:14:16.495Z","updated_at":"2025-04-15T15:20:46.035Z","avatar_url":"https://github.com/TymekDev.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fig\n\u003e _A Config Package with No \"Con\"_\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/fig)](https://cran.r-project.org/package=fig)\n[![R build status](https://github.com/TymekDev/fig/workflows/R-CMD-check/badge.svg)](https://github.com/TymekDev/fig/actions)\n[![Codecov test coverage](https://codecov.io/gh/TymekDev/fig/branch/main/graph/badge.svg)](https://app.codecov.io/gh/TymekDev/fig?branch=main)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)][MIT]\n\u003c!-- badges: end --\u003e\n\n\n## Installation\n```r\ninstall.packages(\"fig\")\n```\n\nTo install latest available version from GitHub use remotes package:\n```r\n# install.packages(\"remotes\")\nremotes::install_github(\"TymekDev/fig\")\n```\n\n\n## Usage\nfig can be used in two different ways:\n1. On a global level using `fig_*` functions\n1. On a class instance level\n\nCheck out the following sections to find the way that suits your needs.\n\n### Using `fig_*` Functions\nThis approach works with no additional prep. It is especially useful if you want\nto access stored values without the hassle to pass an argument through entire\ncodebase. Values stored with `fig_*` live inside fig package making them\naccessible from any place in the code.\n\n```r\nfig_store(\"foo\", 123)\nfig_get(\"foo\") # == 123\n```\nFor more examples see package documentation.\n\n### Using a `Fig` Class Instance\nUsing `Fig` class allows storing values separately in several distinct class\ninstances. If you need a config separation in your code, then `Fig` class is for you.\nNote that, unlike with `fig_*` functions, you have to pass the instance around\nto access values stored in it.\n\n```r\nfig \u003c- Fig$new()\nfig$store(\"foo\", 123)\nfig$get(\"foo\") # == 123\n\nfig2 \u003c- Fig$new()$store(\"foo\", 456)\nfig2$get(\"foo\") # == 456\n```\nFor more examples see package documentation.\n\n\n## Features\n### Precedence\n\u003e :information_source: _This feature is useful if you want to override a stored\n\u003e value without introducing a code change (e.g. log level, API URL, ...)._\n\nfig supports a two level precedence. Every `fig_get()` function and `get()`\nmethod call performs a lookup in a following order:\n1. System environment variables\n1. Stored values\n\n```r\nfig_store_many(foo = 123, bar = 456)\nfig_get_many(\"foo\", \"bar\") # == list(123, 456)\n\n# Environment variable value gets picked over a stored value\nwithr::with_envvar(list(foo = \"xyz\"), {\n  fig_get_many(\"foo\", \"bar\") # == list(\"xyz\", 456)\n})\n\nfig_delete(\"foo\")\n\n# Environment variable value gets picked over a missing stored value\nwithr::with_envvar(list(foo = \"xyz\"), {\n  fig_get(\"foo\") # == \"xyz\"\n})\n\nfig_get(\"foo\") # == NULL\n```\n\n#### Notes\n- As seen in the above example fig does not perform any type coercion. System\n  environment variables are returned as characters, regardless of stored value\n  type.\n- Dots (`.`) in keys are replaced with underscores (`_`) during system\n  environment lookup.\n- System environment lookup is case sensitive.\n\n### Environment Variable Prefix\nThis feature goes in pair with precedence. fig can be configured with\n`env_prefix` argument (default: `\"\"`). It can be provided via `fig_configure()`\n(or `configure()` method) or during `Fig` instance creation.\n\n`env_prefix` determines value prepended to the key before performing a system\nenvironment lookup.\n\n```r\nfig \u003c- Fig$new(env_prefix = \"RCONNECT_\")\nwithr::with_envvar(list(RCONNECT_SERVER = \"example.com\"), {\n  fig$get(\"SERVER\") # == \"example.com\"\n})\n```\n\n### Key Splitting\n\u003e :information_source: _This feature is useful if you want interact\n\u003e (dynamically) with a nested config without a hassle._\n\nfig can be configured with `split_on` argument (default: `\".\"`). It can be\nprovided via `fig_configure()` (or `configure()` method) or during `Fig`\ninstance creation.\n\n`split_on` determines a level delimiter for keys, i.e. with `split_on` set\n`\"foo.bar\"` is treated as `bar` nested under `foo`.\n\n```r\nfig_store(\"foo\", list(bar = 1))\nfig_get(\"foo.bar\") # == 1\n\n# Storage\n# └── foo\n#     └── bar\n#         └── 1\n\nfig_configure(split_on = \"\") # Disable this functionality\nfig_store(\"foo.bar\", 2)\nfig_get(\"foo.bar\") # == 2\n\n# Storage\n# ├── foo\n# │   └── bar\n# │       └── 1\n# └── foo.bar\n#     └── 2\n```\n\n**Note:** this behavior currently is not supported by delete functions and\nmethods.\n\n\n## Examples\n### Working with config\nIf you are using [config](https://github.com/rstudio/config) package and would\nlike to enjoy fig's features, then the suggested approach is to wrap your main\n`config::get()` call in `fig_store_list()` (or `store_list()` method).\n\n```r\n# default:\n#   foo: 123\nfig_store_list(config::get())\n\nfig_get(\"foo\") # == 123\n\nwithr::with_envvar(list(foo = \"xyz\"), {\n  fig_get(\"foo\") # == \"xyz\"\n})\n```\n\nThis way you can use fig functions to have [precedence](#precedence) and [key\nsplitting](#key-splitting) working for retrieving values from your config.\n\n\n\u003c!--\n## Contributing\nTODO\n--\u003e\n\n\n## About\nLicensed under [MIT].\nInspired by [viper](https://github.com/spf13/viper).\nWritten in [Neovim](https://github.com/neovim/neovim).\nTested with [testthat](https://github.com/r-lib/testthat).\nUsed in [radian](https://github.com/randy3k/radian).\n\n\n\u003c!-- Links --\u003e\n[MIT]: https://opensource.org/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftymekdev%2Ffig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftymekdev%2Ffig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftymekdev%2Ffig/lists"}