Skip to contents

Validator function factory for scalar properties. Use it to create functions to be passed as validators for S7 properties.

Usage

prop_scalar_validator(type, allow_null = FALSE)

Arguments

type

A character specifying the type of scalar property. Possible values are "character" and "boolean".

allow_null

A logical indicating whether NULL is an allowed value for the property. When this is used, should be accompanied by defining the property's class argument to the union of NULL and a targeted class, and using NULL as the property's default value.

Value

A function that returns a validation message if the value does not pass the validation, NULL otherwise.

Examples

prop_scalar_validator("character")(5)
#> Error in prop_scalar_validator("character"): could not find function "prop_scalar_validator"
prop_scalar_validator("boolean")(TRUE)
#> Error in prop_scalar_validator("boolean"): could not find function "prop_scalar_validator"