unique-keys: Unique keys

unique-keysR Documentation

Unique keys

Description

A data.table's key need not be unique, but there are frequently circumstances where non-unique keys can wreak havoc. has_unique_key reports the existence of a unique key, and set_unique_key both sets and ensures the uniqueness of keys.

Usage

has_unique_key(DT)

set_unique_key(DT, ...)

Arguments

DT

A data.table

...

keys to set

Value

has_unique_key returns TRUE if DT has a unique key, FALSE otherwise. set_unique_key runs setkey(DT, ...) then checks whether the key is unique, returning the keyed data.table if the key is unique, or an error message otherwise.


hutils documentation built on April 13, 2022, 5:23 p.m.