-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
executable file
·117 lines (86 loc) · 3.44 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
---
output: github_document
---
<!-- 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%"
)
```
# tidyvalidate <a href="https://angelfelizr.github.io/tidyvalidate/"><img src="man/figures/logo.png" align="right" height="139" alt="tidyvalidate website" /></a>
<!-- badges: start -->
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://app.codecov.io/gh/AngelFelizR/tidyvalidate?branch=master)
[](https://github.com/AngelFelizR/tidyvalidate/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
## Overview
tidyvalidate simplifies data validation in R by providing an intuitive interface to the powerful `validate` package. It helps ensure data quality by making it easy to:
- Write clear, expressive validation rules
- Check both column-level and row-level conditions
- Get detailed reports of validation failures
- Integrate validation checks into your data pipeline
The package streamlines common validation tasks while leveraging the robust foundation of the `validate` package and R's error handling system.
## Installation
You can install the development version of tidyvalidate from GitHub:
```r
# Install pak if you haven't already
# install.packages("pak")
# Install tidyvalidate
pak::pak("AngelFelizR/tidyvalidate")
```
## Quick Start
### Basic Validation
Let's validate some data from the built-in `mtcars` dataset:
```{r setup}
library(tidyvalidate)
# Define and run validations
validation_results <- validate_rules(
mtcars,
# Column type validations
mpg_is_numeric = is.numeric(mpg),
hp_is_numeric = is.numeric(hp),
# Business rule validation
mpg_minimum = mpg > 15
)
# View results
validation_results
```
The results show:
- A summary of all validations
- Detailed information about which rows failed the `mpg_minimum` check
### Taking Action on Validation Failures
You can automatically handle validation failures in two ways:
#### 1. Stop Execution on Failure
```{r}
try({
validate_rules(mtcars,
mpg_minimum = mpg > 15
) |>
action_if_problem(
"Critical: Found cars with MPG below minimum threshold"
)
})
```
#### 2. Continue with Warning
```{r}
validation_results <- validate_rules(mtcars,
mpg_minimum = mpg > 15
) |>
action_if_problem(
"Advisory: Some cars have low MPG values",
problem_action = "warning"
)
```
## Key Features
- **Simple Interface**: Write validation rules using familiar R syntax
- **Comprehensive Results**: Get both summary statistics and row-level details
- **Flexible Actions**: Choose between warnings and errors based on severity
- **Pipeline Integration**: Works seamlessly with the pipe operator
- **Detailed Reporting**: Identify exactly which rows failed validation
## Learn More
- Visit our [website](https://angelfelizr.github.io/tidyvalidate/) for full documentation
- Read the [Getting Started](https://angelfelizr.github.io/tidyvalidate/articles/tidyvalidate.html) guide
- Check out the [Reference](https://angelfelizr.github.io/tidyvalidate/reference/index.html) section for detailed function documentation