df <- data.frame(v1 = c(1, 1, 2, 3), v2 = c(4, 5, 5, 6))
duplicates_across_cols(df)
library(magrittr) # for piping operator
# you can use "assert_rows", "in_set", and this function to
# check if specified variables set and all subsets are keys for the data.
correct_df <- data.frame(id = 1:5, sub_id = letters[1:5], work_id = LETTERS[1:5])
correct_df %>%
assert_rows(duplicates_across_cols, in_set(FALSE), id, sub_id, work_id)
# passes because each subset of correct_df variables is key
if (FALSE) {
incorrect_df <- data.frame(id = 1:5, sub_id = letters[1:5], age = c(10, 20, 20, 15, 30))
incorrect_df %>%
assert_rows(duplicates_across_cols, in_set(FALSE), id, sub_id, age)
# fails because age is not key of the data (age == 20 is placed twice)
}
Run the code above in your browser using DataLab