-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
92 lines (70 loc) · 2.76 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
---
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%"
)
```
# testdat <a href='https://socialresearchcentre.github.io/testdat/'><img src='man/figures/logo.png' align="right" height="139" />
<!-- badges: start -->
[](https://lifecycle.r-lib.org/articles/stages.html#maturing)
[](https://github.com/socialresearchcentre/testdat/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/socialresearchcentre/testdat?branch=master)
[](https://CRAN.R-project.org/package=testdat)
<!-- badges: end -->
## Overview
testdat is designed to ease data validation, particularly for complex data
processing, inspired by software unit testing. testdat extends the strong and
flexible unit testing framework already provided by
[testthat](https://testthat.r-lib.org/) with a family of functions and reporting
tools focused on checking of data frames.
Features include:
* A fully fledged test framework so you can spend more time specifying tests and
less time running them
* A set of common methods for simply specifying data validation rules
* Repeatability of data tests (avoid unintentionally breaking your data set!)
* Data-focused reporting of test results
## Installation
You can install the released version of testdat from
[CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("testdat")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("socialresearchcentre/testdat")
```
## Usage
See the [Introduction to
testdat](https://socialresearchcentre.github.io/testdat/articles/testdat.html)
vignette for a detailed introduction.
```{r error=TRUE}
library(testdat, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
x <- tribble(
~id, ~pcode, ~state, ~nsw_only,
1, 2000, "NSW", 1,
2, 3123, "VIC", NA,
3, 2123, "NSW", 3,
4, 12345, "VIC", 3
)
with_testdata(x, {
test_that("id is unique", {
expect_unique(id)
})
test_that("variable values are correct", {
expect_values(pcode, 2000:2999, 3000:3999)
expect_values(state, c("NSW", "VIC"))
expect_values(nsw_only, 1:3) # by default expect_values allows NAs
})
test_that("filters applied correctly", {
expect_base(nsw_only, state == "NSW")
})
})
```