expect_no_duplicates: Check if a data frame has duplicates in a given column. If a...

Description Usage Arguments Value Examples

View source: R/data_expectations.R

Description

Check if a data frame has duplicates in a given column. If a vector is given, check for duplicates in the vector.

Usage

1
2
expect_no_duplicates(df, group_by_column = NA, stop_if_fail = TRUE,
  report_duplicates = TRUE, return_df = TRUE)

Arguments

df

data frame to check

group_by_column

character vector name of column expecting no duplicates

stop_if_fail

T/F for whether to consider failure an error

report_duplicates

T/F for whether to return a partial list of the top duplicates if failure

return_df

T/F whether to end function with dataframe input (as in if a check in part of a pipe)

Value

several options depending on whether it fails or succeeeds

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
expect_no_duplicates(mtcars, "cyl")
# [1] "top duplicates..."
# A tibble: 3 x 2
# Groups:   cyl [3]
#cyl     n
#<dbl> <int>
#1     4    11
#2     6     7
#3     8    14
# Error in ifelse(stop_if_fail, stop(paste0("Duplicates detected in column: ",  :
                                                Duplicates detected in column: cyl

expect_no_duplicates(rownames(mtcars))
# [1] "no vector duplicates...OK"

dgarmat/dgfunctionpack documentation built on May 17, 2020, 9:58 p.m.