has_class: Returns TRUE if data.frame columns have a specified class

View source: R/utils.R

has_classR Documentation

Returns TRUE if data.frame columns have a specified class

Description

This is meant to be used with ‘assertr'’s 'verify' function to check for the existence of a specific column class in a 'data.frame' that is piped to 'verify'.

Usage

has_class(..., class)

Arguments

...

An arbitrary amount of quoted column names to check for. Character vectors of names are accepted too.

class

Expected class for chosen columns.

Value

TRUE if all classes are correct, FALSE if not

Examples


verify(mtcars, has_class("mpg", "wt", class = "numeric"))

# the column names can also be given as a character vector
verify(mtcars, has_class(c("mpg", "wt"), class = "numeric"))

library(magrittr)   # for pipe operator

## Not run: 
mtcars %>%
  verify(has_class("mpg", class = "character"))  # fails

## End(Not run)


assertr documentation built on Nov. 13, 2026, 1:12 a.m.