This function checks if there is exactly one row per group in the provided dataframe. If there are multiple rows per group, the assertion fails.

check_no_duplicates_in_group(
  dataframe,
  group_variables = NULL,
  assertion_fail = "stop"
)

Arguments

dataframe

The dataframe to be checked.

group_variables

The group variables as a character vector. The default is NULL.

assertion_fail

How the function reacts to a failure. This can be a "warning", where only a warning is given on the failure, or a "stop", where the function execution is stopped and the message is displayed, or an "AssertCollection", where the failure message is added to an assertion collection.

Examples

# Create a dataframe with some groups having more than one row
dataframe <- data.frame(a = c(1, 1, 2), b = c(2, 2, 3), c = c("x", "x", "y"))
# Check the uniqueness of rows per group
check_no_duplicates_in_group(dataframe)