checkmate
checkmate copied to clipboard
add unique, unique.byrow, unique.bycol to check_matrix() and friends
check_vector() helpfully provides a unique argument.
It would be really nice to have this for two-dimensional objects as well, where it's often important to be unique overall, or by row or by column.
Perhaps something like:
# helper: check unique by column
check_unique_in_column <- function(x) {
duplicates <- apply(X = x, MARGIN = 2, FUN = function(x) {
duplicated(x = x, incomparables = NA)
})
if (any(duplicates)) {
return("must only have unique entries by column")
} else {
return(TRUE)
}
}
assert_unique_in_column <- makeAssertionFunction(check_unique_in_column)
I am aware that much of the stuff that checkmate does under the hood is written in C, which unfortunately I cannot do.
If any of these additions could also be helpful in R, I'd be happy to open respective PRs, though I might need some guidance to make sure any potential additions sit well with the overall design and infrastructure.