check_internal: Internal function for checking multiple/single-response...

Description Usage Arguments Details Value See Also Examples

View source: R/check_internal.R

Description

This is low-level function intended for programming. For interactive usage see functions mult and sngl.

Usage

1
2
3
4
5
6
7
8
check_internal(dfs, values = NULL, exclusive = NULL, mult = FALSE,
  no_dup = mult, cond = NULL, subset = NULL)

## S3 method for class 'check'
print(x, error_num = 20, ...)

## S3 method for class 'check'
summary(object, skip_details = FALSE)

Arguments

dfs

Vector/data.frame/matrix that should be checked.

values

Valid values. All other values will be considered incorrect.

exclusive

Numeric/character values. These values should be exclusive. All other values should be NA if any of exclusive values exists in row.

mult

Logical. Should we check dfs as multiple response question?

no_dup

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

cond

Logical vector. TRUE indicated rows in dfs that should contain valid values. In other rows all dfs values should be NA. It used for questions that were asked by condition on answer on previous questions.

subset

Logical vector. TRUE indicated rows in dfs that should be checked. Other rows will be ignored.

x

Check object for printing.

error_num

Numeric. How many errors should be printed?

object

Check object for summary.

skip_details

Logical. For more terse summary.

Details

'mult=TRUE' for multiple response questions means that it is allowed to have NA values in row. It is only necessary for multiple response questions that each row will have at least one non-NA values. This function checks multiple response questions only with categorical coding. For checking multiple response questions with dichotomous coding see dmult. If 'mult=FALSE' all values should be non-NA. However one can put NA in 'values' argument. Then NA will be considered valid. By default if 'mult=TRUE' then no_dup also is TRUE. If 'values' is missing than all values considered valid except NA. 'check' report only for first error in row. If there are other errors for this case they will be reported only after correction of first error.

Value

check_internal return object of class 'check'. It is data.frame that contains check result for each row of dfs and description for each error if any of them exists. print.check invisibly returns its argument x. summary.check returns list with summary check.

See Also

mult, mult_, sngl, sngl_, dmult

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

## Example 1 ##

# 4 errors: 2 missing, 2 invalid codes
check_internal(ProductTestRaw$s2b,values=2:3)

## 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
check_internal(select(ProductTestRaw,a1_1:a1_6),values=valid_a1,
     mult = TRUE, exclusive=c(1,2,99))

## 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.
check_internal(select(ProductTestRaw,a4_1:a4_6),
     values=valid_a4,mult = TRUE, exclusive=99,
      cond = ProductTestRaw$a3 %in%  1:4)

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