Learn R Programming

schemate (version 0.1.0)

schema_validate: Validate input against a schema

Description

schema_validate() validates an R object against a SchemaDoc, SchemaFlat, or compiled flat schema node.

Usage

schema_validate(schema, x, mode = "assert", name = NULL, ...)

Value

In "assert" mode, invisibly returns x or throws an error. In "check" mode, returns TRUE or a diagnostic string. In "test" mode, returns TRUE or FALSE. In "expect" mode, returns a testthat-style expectation object.

Arguments

schema

A SchemaDoc, SchemaFlat, or compiled flat schema node.

x

Input object to validate.

mode

One of "assert", "check", "test", or "expect".

name

Optional display name used in validation messages.

...

Reserved for future extension.

Examples

Run this code
schema <- schema_doc(list(
    check = list(kind = "list"),
    fields = list(id = list(check = list(kind = "int", lower = 1)))
))
schema

schema_validate(schema, list(id = 1L), mode = "test")
schema_validate(schema, list(id = 0L), mode = "check", name = "payload")

Run the code above in your browser using DataLab