expect_same_number_of_rows: Check if a dataframe has the same number of rows as another,...

Description Usage Arguments Value Examples

View source: R/data_expectations.R

Description

Check if a dataframe has the same number of rows as another, or else 0 rows. If vectors are given the lengths of the vectors are compared.

Usage

1
2
expect_same_number_of_rows(df1, df2 = data.frame(),
  stop_if_fail = TRUE, report_rowcount = FALSE, return_df = TRUE)

Arguments

df1

dataframe or vector to check (required)

df2

optional second dataframe or vector to compare (if not given, defaults to zero row data frame)

stop_if_fail

T/F for whether to consider failure an error

report_rowcount

T/F for whether to return the number of rows

return_df

T/F whether to end function with dataframe 1 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
expect_same_number_of_rows(mtcars, mtcars)
# [1] "Same number of rows...OK"

expect_same_number_of_rows(mtcars, iris)
# Error in ifelse(stop_if_fail, stop(paste0("Different number of rows: ",  :
#    Different number of rows: 32 vs: 150

expect_same_number_of_rows(mtcars)
# Error in ifelse(stop_if_fail, stop(paste0("Different number of rows: ",  :
#    Different number of rows: 32 vs: 0

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