# Join utilities #' Test the join between two sets of identifiers #' #' @param x A vector of identifiers to check against `y`. #' @param y A vector of identifiers to look for a match in. #' @param distinct Logical. Should duplicate values of `x` and `y` be removed #' before testing? Default is `TRUE`. #' #' @return Invisibly returns `NULL`; prints a formatted summary of match #' statistics to the console via [writeLines()]. #' @export #' #' @examples #' x <- LETTERS #' y <- c(letters, LETTERS) #' match_test(x, y) match_test <- function(x, y, distinct = TRUE) { if (distinct) { x <- unique(x) y <- unique(y) } # TODO: DO not report 100% if there is even 1 mismatch xiny <- sum(x %in% y) total_x <- length(x) pct_x <- round(100 * xiny / total_x, 2) yinx <- sum(y %in% x) total_y <- length(y) pct_y <- round(100 * yinx / total_y, 2) header <- if (distinct) "Distinct Matches" else "All Values" lines <- c( paste0("**** ", header, " ****"), "", "X in Y", sprintf("Of the %d X values, %d (%s%%) were matched.", total_x, xiny, format(pct_x, nsmall = 2)), strrep("*", 40), "", "Y in X", sprintf("Of the %d Y values, %d (%s%%) were matched.", total_y, yinx, format(pct_y, nsmall = 2)), strrep("*", 38) ) writeLines(lines) invisible(NULL) }