check_dataframe() and check_is_dataframe_not_tibble()
verify whether an object is a data frame and not a tibble.
check_dataframe() raises an error if the object is not a
data frame or is a tibble. check_is_dataframe_not_tibble() returns
TRUE if the object is a data frame (not a tibble), and FALSE
otherwise.
Value
check_dataframe(): Returns the input object or raises an error if the condition is not met.check_is_dataframe_not_tibble(): Logical value,TRUEif the object is a data frame but not a tibble, andFALSEotherwise.
Examples
# Examples for check_dataframe()
# -----------------------------------------
df <- data.frame(a = 1:3, b = c(NA, 2, 3))
print(df)
#>   a  b
#> 1 1 NA
#> 2 2  2
#> 3 3  3
check_dataframe(df)
#>   a  b
#> 1 1 NA
#> 2 2  2
#> 3 3  3
library(tibble)
tib <- tibble(a = 1:3, b = c(NA, 2, 3))
print(tib)
#> # A tibble: 3 × 2
#>       a     b
#>   <int> <dbl>
#> 1     1    NA
#> 2     2     2
#> 3     3     3
try(check_dataframe(tib))
#> Error in check_dataframe(tib) : 
#>   Expected 'dat' to be a data frame (not tibble) but got tbl_df tbl data.frame
A <- matrix(1:6, nrow = 2)
print(A)
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    2    4    6
try(check_dataframe(A))
#> Error in check_dataframe(A) : 
#>   Expected 'dat' to be a data frame (not tibble) but got matrix array
vec <- c(1, 2, 3)
print(vec)
#> [1] 1 2 3
try(check_dataframe(vec))
#> Error in check_dataframe(vec) : 
#>   Expected 'dat' to be a data frame (not tibble) but got numeric
list_obj <- list(a = 1, b = 2)
print(list_obj)
#> $a
#> [1] 1
#> 
#> $b
#> [1] 2
#> 
try(check_dataframe(list_obj))
#> Error in check_dataframe(list_obj) : 
#>   Expected 'dat' to be a data frame (not tibble) but got list
# Examples for check_is_dataframe_not_tibble()
# --------------------------------------------
check_is_dataframe_not_tibble(df)
#> [1] TRUE
check_is_dataframe_not_tibble(tib)
#> [1] FALSE
check_is_dataframe_not_tibble(A)
#> [1] FALSE
check_is_dataframe_not_tibble(vec)
#> [1] FALSE
check_is_dataframe_not_tibble(list_obj)
#> [1] FALSE