/
chk-unique.R
39 lines (38 loc) · 977 Bytes
/
chk-unique.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#' Check Unique
#'
#' @description
#' Checks if unique using
#'
#' `!anyDuplicated(x, incomparables = incomparables)`
#'
#' @inheritParams params
#' @inherit params return
#'
#' @family chk_misc
#'
#' @examples
#' # chk_unique
#' chk_unique(c(NA, 2))
#' try(chk_unique(c(NA, NA, 2)))
#' chk_unique(c(NA, NA, 2), incomparables = NA)
#' @export
chk_unique <- function(x, incomparables = FALSE, x_name = NULL) {
if (vld_unique(x, incomparables = incomparables)) {
return(invisible(x))
}
if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x))
abort_chk(x_name, " must be unique", x = x, incomparables = incomparables)
}
#' @describeIn chk_unique Validate Unique
#'
#' @examples
#' # vld_unique
#' vld_unique(NULL)
#' vld_unique(numeric(0))
#' vld_unique(c(NA, 2))
#' vld_unique(c(NA, NA, 2))
#' vld_unique(c(NA, NA, 2), incomparables = NA)
#' @export
vld_unique <- function(x, incomparables = FALSE) {
!.anyDuplicated(x, incomparables = incomparables)
}