check_if: Functions for checking conditional questions/subset of data.

Description Usage Arguments Details Value See Also Examples

View source: R/check_if.R

Description

These functions are designed for working with piping operator %>% from 'magrittr' package.

Usage

1
2
3
4
5
6
7
check_if(.data, expr)

.check_if(expr)

check_subset(.data, expr)

.check_subset(expr)

Arguments

.data

data.frame for checking

expr

Logical vector/expression.

Details

TRUE in expr vector indicated rows in .data that should contain valid values. For check_if in other rows all .data values should be NA. It used for questions that were asked by condition on answer from previous questions. For check_subset values in other rows will be ignored - they are all will be considered as valid.

Value

These functions returns object of class 'chk_if'. It is suited for consumption by functions: sngl,mult,dmult, error_if and move. Also it can be accepted by next check_if and/or check_subset.

See Also

sngl, mult, dmult, error_if and move

Examples

 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
library(dplyr)
data(ProductTestRaw)
data(codeframe)

## Example 1 ##

valid_a4 = make_labels(codeframe$dislikes_in_appearance)
# question a4 was asked only if codes 1-4 marked in a3
# 3 errors: 1 missing value, 1 invalid code, 1 code in case of a3 in 5-7.
ProductTestRaw  %>%
     check_if(a3 %in% 1:4)  %>%
     mult(a4_1:a4_6)(valid_a4,exclusive=99)  %>%
     report

## Example 2 ##

# There are no errors in question s2b in cell 2.
ProductTestRaw  %>%
     check_subset(cell %in% 2) %>%
     sngl(s2b)(2,3)  %>%
     report

## Example 3 ##

# There are no errors in question a4 in cell 2.
ProductTestRaw  %>%
     check_subset(cell %in% 2)  %>%
     check_if(a3 %in% 1:4)  %>%
     mult(a4_1:a4_6)(valid_a4,exclusive=99)  %>%
     report

gdemin/cleanr documentation built on May 16, 2019, 11:14 p.m.