sngl: Functions for checking multiple/single-response questions for...

Description Usage Arguments Details Value See Also Examples

View source: R/sngl.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
mult(..., no_dup = TRUE, show = NULL)

.mult(..., no_dup = TRUE, show = NULL)

mult_(..., .dots, no_dup = TRUE, show = NULL)

sngl(..., no_dup = FALSE, show = NULL)

.sngl(..., no_dup = FALSE, show = NULL)

sngl_(..., .dots, no_dup = FALSE, show = NULL)

report(.data)

Arguments

...

Comma separated list of unquoted variable names. You can use special functions such as 'starts_with', 'ends_with', 'contains' and etc. For details see select in package 'dplyr'.

no_dup

Logical. Should we check for absence of duplicated values in each row?

show

Additional variables (such as 'id') that should be shown with report about errors.

.dots

Use mult_()/sngl_() to do standard evaluation. See vignette("nse") in dplyr package for details

.data

data.frame

Details

Supposed usage is: checked_data.frame %>% mult(var_names)(valid_values,exclusive) or checked_data.frame %>% mult(var_names)(valid_values) Only valid values should be exists in var_names. All other values will be considered incorrect. For multiple response questions (mult) it is only necessary that each row will have at least one valid non-NA values. If any of exclusive values exists in row all other values should be NA . mult function checks multiple response questions only with categorical coding. For checking multiple response questions with dichotomous coding see dmult. If 'values' is missing than all values considered valid except NA. Only first error in the row is reported. If there are other errors for this case they will be reported only after correction of first error.

Value

mult/sngl functions returns another function value(.data,...,exclusive). That function accepts data.frame and valid values. See examples. 'value' function return data.frame with attribute with results of checking. report print results of checking and invisibly returns checked data.frame.

See Also

check_internal, select, %>%, dmult, error_if, 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
library(dplyr)
data(ProductTestRaw)

## Example 1 ##

# 4 errors: 2 missing, 2 invalid codes
ProductTestRaw  %>%
         sngl(s2b)(2:3)  %>%
         report

## Example 2 ##

data(codeframe)
valid_a1 = make_labels(codeframe$likes)

# Exclusive values
# 1 Liked everything
# 2 Disliked everything
# 99 Hard to say

# 5 errors: 1 missing value, 1 invalid code, 1 code duplication,
# 2 non-exclusive values.
# Additional variable 'id' also is shown.
ProductTestRaw  %>%
         mult(a1_1:a1_6,show = id)(valid_a1,exclusive=c(1,2,99))  %>%
         report

## Example 3 ##

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 4 ##

# Usage in programming (e. g. in cycle 'for')

checked_vars = c("a3","a22","b3","b23")
# there is one error in a22

for (each_var in checked_vars){
     ProductTestRaw  %>%
         sngl_(each_var)(1:7)  %>%
         report
}

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