isKey: Check if a variable qualifies as a key

Description Usage Arguments Details Value See Also Examples

View source: R/isKey.R

Description

A checkFunction that checks if v is a key, that is, if every observation has a unique value in v and v is not a numeric/integer nor a Date variable. This function is intended for use as a precheck in makeDataReport.

Usage

1
isKey(v)

Arguments

v

A variable (vector) to check. All variable types are allowed.

Details

Note that numeric or integer variables are not considered candidates for keys, as truly continuous measurements will most likely result in unique values for each observation.

Value

A checkResult with three entires: $problem (a logical indicating whether v is a key), $message (if a problem was found, the following message: "The variable is a key (distinct values for each observation).", otherwise "") and $problemValues (always NULL).

See Also

check, allCheckFunctions, checkFunction, checkResult

Examples

1
2
3
4
5
keyVar <- c("a", "b", "c", "d", "e", "f")
notKeyVar <- c("a", "a", "b", "c", "d", "e", "f")

isKey(keyVar)
isKey(notKeyVar)

ekstroem/cleanR documentation built on Jan. 31, 2022, 8:58 a.m.