Learn R Programming

cheese (version 0.0.3)

type_match: Check if an object is at least one (or none) of the specified types

Description

This is a utility function to assess whether an object inherits at least one (or none) of the user-specified classes.

Usage

type_match(
    object,
    types,
    negated = FALSE
)

Arguments

object

Any R object.

types

A character vector of classes to check against object.

negated

Should TRUE be returned if object inherits no types? Defaults to FALSE.

Value

A logical indicator

Examples

Run this code
# NOT RUN {
require(tidyverse)

#1) Default
heart_disease %>%
    map_lgl(
        type_match,
        types = "numeric"
    )

#2) Use negation
heart_disease %>%
    map_lgl(
        type_match,
        types = "numeric",
        negated = TRUE
    )

#3) Multiple types
heart_disease %>%
    map_lgl(
        type_match,
        types = c("numeric", "factor")
    )

#4) Check other objects
heart_disease %>%
    glm(Sex ~ Age, data = ., family = "binomial") %>%
    type_match(
        types = "glm"
    )
# }

Run the code above in your browser using DataLab