-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
164 lines (122 loc) · 5.13 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
<!-- badges: start -->
[![Lifecycle: superseded](https://img.shields.io/badge/lifecycle-superseded-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html#superseded)
[![R-CMD-check](https://github.com/poissonconsulting/checkr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/checkr/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/poissonconsulting/checkr/graph/badge.svg)](https://app.codecov.io/gh/poissonconsulting/checkr)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit/)
[![JOSS](http://joss.theoj.org/papers/10.21105/joss.00624/status.svg)](https://doi.org/10.21105/joss.00624)
<!-- badges: end -->
# checkr
`checkr` has been superseded by the [`chk`](https://github.com/poissonconsulting/chk) package.
`checkr` is a light-weight R package of expressive, assertive, pipe-friendly functions to check the properties of common R objects.
In the case of failure the functions, which are designed to be used in scripts and packages,
issue informative error messages.
For an overview of the functions see the `checkr-naming` vignette and for a comparison with similar packages see the `assertive-programming` vignette.
## Demonstration
The following code demonstrates the `check_data()` function
```{r, error = TRUE}
library(checkr)
# the starwars data frame in the dplyr package fails many of these checks
check_data(dplyr::starwars, values = list(
height = c(66L, 264L),
name = "",
mass = c(20,1358, NA),
hair_color = c("blond", "brown", "black", NA),
gender = c("male", "female", "hermaphrodite", "none", NA)),
order = TRUE, nrow = c(81, 84), key = "hair_color", error = FALSE)
```
## Syntax
`checkr` uses objects to check
the values of other objects using an elegant and expressive syntax.
#### Class
To check the class simply pass an object of the desired class.
```{r, error = TRUE}
y <- c(2,1,0,1,NA)
check_vector(y, values = numeric(0))
check_vector(y, values = integer(0))
```
#### Missing Values
To check that a vector does not include missing values pass a single non-missing value (of the correct class).
```{r, error = TRUE}
check_vector(y, 1)
```
To allow it to include missing values include a missing value.
```{r}
check_vector(y, c(1, NA))
```
And to check that it only includes missing values only pass a missing value (of the correct class)
```{r, error = TRUE}
check_vector(y, NA_real_)
```
#### Range
To check the range of a vector pass two non-missing values (as well as the missing value if required).
```{r, error = TRUE}
check_vector(y, c(0, 2, NA))
check_vector(y, c(-1, -10, NA))
```
#### Specific Values
To check the vector only includes specific values pass three or more non-missing values or
set `only = TRUE`.
```{r, error = TRUE}
check_vector(y, c(0, 1, 2, NA))
check_vector(y, c(1, 1, 2, NA))
check_vector(y, c(1, 2, NA), only = TRUE)
```
## Naming Objects
By default, the name of an object is determined from the function call.
```{r, error=TRUE}
check_vector(list(x = 1))
```
This simplifies things but results in less informative error messages when used in a pipe.
```{r, error = TRUE}
library(magrittr)
y %>% check_list()
```
The argument `x_name` can be used to override the name.
```{r, error = TRUE}
y %>% check_list(x_name = "y")
```
## Scalars
The four wrapper functions
`check_lgl()`, `check_int()`, `check_dbl()` and `check_str()` check whether an object
is an attribute-less non-missing scalar logical (flag), integer, double (number) or character (string).
They are really useful for checking the types of arguments in functions
```{r, error = TRUE}
fun <- function(x) { check_lgl(x)}
fun(x = NA)
fun(x = TRUE)
fun(x = 1)
```
Additional scalar wrappers are `check_date()` and `check_dttm()` for scalar Date and POSIXct objects.
Alternatively you can roll your own using the more general `check_scalar()` function.
## Installation
To install the latest development version from [r-universe](https://poissonconsulting.r-universe.dev/checkr).
```r
install.packages("checkr", repos = c("https://poissonconsulting.r-universe.dev", "https://cloud.r-project.org"))
```
To install the latest development version from [GitHub](https://github.com/poissonconsulting/checkr)
```r
# install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/stable/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))
pak::pak("poissonconsulting/checkr")
```
## Citation
```{r, comment="", echo=FALSE}
citation(package = "checkr")
```
## Contribution
Please report any [issues](https://github.com/poissonconsulting/checkr/issues).
[Pull requests](https://github.com/poissonconsulting/checkr/pulls) are always welcome.
## Code of Conduct
Please note that the checkr project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms