is_unique: Test for uniquenes of records

Description Usage Arguments Value See Also Examples

View source: R/syntax.R

Description

Test for uniqueness of columns or combinations of columns.

Usage

1
2
3
4
5

Arguments

...

When used in a validation rule: a bare (unquoted) list of variable names. When used directly, a comma-separated list of vectors of equal length.

Value

For is_unique A logical vector that is FALSE for each record that has a duplicate.

For all_unique a single TRUE or FALSE.

For number_unique a single number representing the number of unique values or value combinations in the arguments.

See Also

Other cross-record-helpers: contains_exactly(), do_by(), exists_any(), hb(), hierarchy(), is_complete(), is_linear_sequence()

Examples

1
2
3
4
5
6
7
8
d <- data.frame(X = c('a','b','c','b'), Y = c('banana','apple','banana','apple'), Z=1:4)
v <- validator(is_unique(X, Y))
values(confront(d, v))

# example with groupwise test
df <- data.frame(x=c(rep("a",3), rep("b",3)),y=c(1,1,2,1:3))
v <- validator(is_unique(y, by=x))
values(confront(d,v))

validate documentation built on Oct. 7, 2021, 9:19 a.m.