lgl_vec {dataclass}R Documentation

Validator: Check if element is a logical

Description

This function is used to check whether something is a logical. You can use this function to check the length of a logical vector. You can also specify the level of a violation. If level is set to "warn" then invalid inputs will warn you. However, if level is set to "error" then invalid inputs will abort.

Usage

lgl_vec(max_len = Inf, min_len = 1, level = "error", allow_na = FALSE)

Arguments

max_len

The maximum length of a logical element

min_len

The minimum length of a logical element

level

Setting "warn" throws a warning, setting "error" halts

allow_na

Should NA values be allowed?

Value

A function with the following properties:

* Checks whether something is a logical vector * Determines whether the check will throw warning or error * Optionally checks for element length

Examples

# Define a dataclass for testing logicals:
my_dataclass <-
  dataclass(
    bool = lgl_vec()
  )

# `bool` must be a logical vector of any length!
my_dataclass(
  bool = TRUE
)

[Package dataclass version 0.3.0 Index]