Skip to contents

Checks that the key columns identify each row once, and stops with the number of duplicated keys and a few examples otherwise. Run it before writing: DuckDB tables built for "delete then insert" updates have no primary key, so uniqueness is enforced here (see create_schema()).

Usage

check_unique(data, keys, what = deparse1(substitute(data)))

Arguments

data

A data frame.

keys

Character. Key columns.

what

Character. Name used in the error message (by default the expression passed as data).

Value

data, invisibly.

Examples

check_unique(data.frame(doc_id = c("a:1", "a:2")), "doc_id")
try(check_unique(data.frame(doc_id = c("a:1", "a:1")), "doc_id"))
#> Error in check_unique(data.frame(doc_id = c("a:1", "a:1")), "doc_id") : 
#>   1 duplicated value of key doc_id in data.frame(doc_id = c("a:1",
#> "a:1")).
#> ℹ For example: "a:1".