expect_class: Class validation

Description Usage Arguments Examples

View source: R/testing.R

Description

Check whether columns of a data frame match are of a certain class and return an informative warning otherwise.

Usage

1
expect_class(data, class_mapping, must_check_all)

Arguments

data

A data frame to check.

class_mapping

A data frame that contains two columns: name and class, whereas the values in name indicate the name of a column to check, class indicates the target class of the column.

must_check_all

Whether or not all columns need to be checked in order to avoid a warning.

Examples

1
2
3
4
5
6
7
8
9
library(tibble)
library(magrittr)
class_mapping <- tribble(
  ~ name,  ~ class,
  "cyl", "integer",
  "model", "character"
)
rownames_to_column(mtcars, var= "model") %>%
  gitsum:::expect_class(class_mapping, must_check_all = FALSE)

lorenzwalthert/gitsum documentation built on Jan. 17, 2021, 9:34 p.m.