is_: Check whether object is the right class, size and type

View source: R/is_are.R

is_R Documentation

Check whether object is the right class, size and type

Description

Checks both the class, size and type of an object. Returns a logical or an error if false.

Usage

is_(x, class = NULL, size = NULL, type = NULL, error_on_false = F)

Arguments

x

(any object) The object to test.

class

(chr vector) The accepted classes. This is checked with is.

size

(num vector) The accepted lengths. This is checked with get_dims.

type

(chr vector) The accepted types. This is checked with typeof.

error_on_false

(log scalar) Whether to throw an error instead of returning false (default false).

Details

Vectors are treated as 1-dimensional.

Value

Logical scalar or error.

Examples

is_(iris, class = "data.frame") #check for one class
is_(iris, class = c("data.frame", "logical", "matrix")) #can check for multiple classes
is_(iris, class = "data.frame", size = c(150, 5)) #check for one class and size
is_(iris, size = c(150, 5)) #check for size
is_(iris, size = 1) #check for wrong size
is_(iris, type = "list") #check for type
!is_(iris, type = "factor") #check for wrong type
is_(iris, class = "list", error_on_false = T) #check for one class, error
is_(1:3, class = "numeric")

Deleetdk/kirkegaard documentation built on April 1, 2024, 2:23 a.m.