Validate that a vector has only unique values
Source:R/validation-uniqueness.R
hasOnlyDistinctValues.Rd
Validate that a vector has only unique values
Usage
hasOnlyDistinctValues(values, na.rm = TRUE)
validateHasOnlyDistinctValues(values, na.rm = TRUE)
Arguments
- values
An array of values
- na.rm
Logical to decide if missing values should be removed from the duplicate checking. Note that duplicate
NA
values are flagged ifna.rm=FALSE
.
Value
hasOnlyDistinctValues
returnsTRUE
if all values are unique.validateHasOnlyDistinctValues()
returnsNULL
if only unique values present, otherwise produces error.
Examples
hasOnlyDistinctValues(c("x", "y"))
#> [1] TRUE
hasOnlyDistinctValues(c("x", "y", "x"))
#> [1] FALSE
hasOnlyDistinctValues(c("x", NA, "y", NA), na.rm = FALSE)
#> [1] FALSE
hasOnlyDistinctValues(c("x", NA, "y", NA), na.rm = TRUE)
#> [1] TRUE
validateHasOnlyDistinctValues(c("x", "y")) # NULL
#> NULL
# validateHasOnlyDistinctValues(c("x", "y", "x")) # error