Learn R Programming

keyed (version 0.1.3)

lock_unique: Assert that columns are unique

Description

Checks that the combination of specified columns has unique values. This is a point-in-time assertion that either passes silently or fails.

Usage

lock_unique(.data, ..., .strict = FALSE)

Value

Invisibly returns .data (for piping).

Arguments

.data

A data frame.

...

Column names (unquoted) to check for uniqueness.

.strict

If TRUE, error on failure. If FALSE (default), warn.

Examples

Run this code
df <- data.frame(id = 1:3, x = c("a", "b", "c"))
lock_unique(df, id)

# Fails with warning
df2 <- data.frame(id = c(1, 1, 2), x = c("a", "b", "c"))
lock_unique(df2, id)

Run the code above in your browser using DataLab