Checks to see if the rows of the input data.table are unique for each combination of the id columns.

assert_is_unique_dt(dt, id_cols)

identify_non_unique_dt(dt, id_cols)

Arguments

dt

[data.table()]
Input data.table to check rows are unique.

id_cols

[character()]
ID columns that uniquely identify each row of dt.

Value

identify_non_unique_dt returns a data.table with problematic rows only, includes a 'count' column identifying how many times each combination of id columns is in the dataset. assert_is_unique_dt returns nothing but throws an error if identify_non_unique_dt returns a non empty data.table.

See also

assertable::assert_ids to check that all unique combinations of specified id variables list, this is appropriate when you expect your dataset to be square.

Examples

input_dt <- data.table::data.table(location = "France", year = 2010, sex = "female", age_start = 0:95, value1 = 2, value2 = 4) id_cols <- c("location", "year", "sex", "age_start") non_unique_dt <- identify_non_unique_dt(input_dt, id_cols) assert_is_unique_dt(input_dt, id_cols)
#> [1] TRUE