Learn R Programming

dm (version 0.0.5.9000)

check_key: Test if a column (combination) is unique key of a table

Description

check_key() accepts a data frame and, optionally, columns. It throws an error if the specified columns (or all columns, if no columns are specified) are NOT a unique key of the data frame. If the columns given in the ellipsis ARE a key, the data frame itself is returned silently, so that it can be used for piping.

Usage

check_key(.data, ...)

Arguments

.data

The data frame whose columns should be tested for key properties.

...

The names of the columns to be checked. If none are specified, then all columns together are tested for the key property.

One or more unquoted expressions separated by commas. Variable names can be treated as if they were positions, so you can use expressions like x:y to select ranges of variables.

The arguments in ... are automatically quoted and evaluated in a context where column names represent column positions. They also support unquoting and splicing. See vignette("programming") for an introduction to these concepts.

See select helpers for more details and examples about tidyselect helpers such as starts_with(), everything(), ...

Examples

Run this code
# NOT RUN {
data <- tibble::tibble(a = c(1, 2, 1), b = c(1, 4, 1), c = c(5, 6, 7))
# this is failing:
try(check_key(data, a, b))

# this is passing:
check_key(data, a, c)
# }

Run the code above in your browser using DataLab