Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jakubnowicki/fixtures
Generate mock data from yaml configuration.
https://github.com/jakubnowicki/fixtures
fixtures mock-data mock-data-generator r test-data-generator yaml-configuration
Last synced: 12 days ago
JSON representation
Generate mock data from yaml configuration.
- Host: GitHub
- URL: https://github.com/jakubnowicki/fixtures
- Owner: jakubnowicki
- License: other
- Created: 2020-08-08T23:35:51.000Z (over 4 years ago)
- Default Branch: develop
- Last Pushed: 2023-01-26T14:36:50.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T18:22:53.844Z (28 days ago)
- Topics: fixtures, mock-data, mock-data-generator, r, test-data-generator, yaml-configuration
- Language: R
- Homepage: https://jakubnowicki.github.io/fixtuRes/
- Size: 535 KB
- Stars: 16
- Watchers: 2
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fixtuRes
![R-CMD-check](https://github.com/jakubnowicki/fixtuRes/workflows/R-CMD-check/badge.svg)
[![version](https://www.r-pkg.org/badges/version/fixtuRes)](https://CRAN.R-project.org/package=fixtuRes)
[![cranlogs](https://cranlogs.r-pkg.org/badges/fixtuRes)](https://CRAN.R-project.org/package=fixtuRes)
[![total](https://cranlogs.r-pkg.org/badges/grand-total/fixtuRes)](https://CRAN.R-project.org/package=fixtuRes)Generate mock data in R using YAML configuration.
## Installation
You can install a stable release from CRAN repository:
```r
install.packages("fixtuRes")
```You can install the latest version with `remotes`:
```r
remotes::install_github("jakubnowicki/fixtuRes@develop")
```## Usage
`fixtuRes` package provides a set of tools that allow generating random mock data for testing or to use during development. Main one, R6 class named `MockDataGenerator` is a data generator fed with a configuration
provided in a `yaml` file. You can also use lower level functions designed to generate data frames, vectors or single values.### MockDataGenerator
Let's say, that you need a data frame with 5 columns. First one should be called "id" and contain a random integer from 100 to 999. Second, "code",
should be a string of three capital letters. Third one, "metric", is a
random numeric value in -10, 10 range. Fourth, called "type", can be
one of "TEST", "PROD", "QUA". Finally, the fifth one is a boolean called
"pass". It should be set to TRUE if metric is above 3, otherwise it should
be set to FALSE. To create a data frame that follows those rules you will
need a configuration (you can find prepared file [here](https://github.com/jakubnowicki/fixtuRes/blob/master/examples/basic_example.yaml)):```yaml
my_data_frame:
columns:
id:
type: integer
min: 100
max: 999
unique: TRUE
code:
type: string
pattern: "[A-Z]"
length: 3
metric:
type: numeric
min: -10
max: 10
type:
type: set
set: ["TEST", "PROD", "QUA"]
pass:
type: calculated
formula: "metric > 3"
```Now you can pass this configuration to a new `MockDataGenerator` object:
```r
my_mock_generator <- fixtuRes::MockDataGenerator$new("path-to-my-configuration.yml")
```And just create a data frame you have just designed:
```r
my_mock_generator$get_data("my_data_frame")
```For a detailed description of configuration check [this document](https://jakubnowicki.github.io/fixtuRes/articles/configuration.html).
Low level functions are described in R package documentation.
## Showcase
You can check `fixtuRes` in action in [Fake Data Generator](https://jakubnowicki.shinyapps.io/fake-data-generator/).
It enables live preview of your YAML configuration, downloading YAML itself
and generated dataset.