check_schema_df: Check a data frame of data against a JSON Schema

View source: R/check-schema-df.R

check_schema_dfR Documentation

Check a data frame of data against a JSON Schema

Description

Each row of the data frame will be converted to JSON and validated against the given schema.

Usage

check_schema_df(
  df,
  schema,
  success_msg = "Data is valid against the schema",
  fail_msg = "Data is invalid against the schema"
)

Arguments

df

A data frame whose rows will be converted into JSON and validated

schema

Contents of the json schema, or a filename containing a schema.

success_msg

Message indicating the check succeeded.

fail_msg

Message indicating the check failed.

Value

A condition object indicating whether the data is valid against the schema.

Examples

if (requireNamespace("jsonvalidate", quietly = TRUE) &
  requireNamespace("jsonlite", quietly = TRUE)) {
  dat <- data.frame(
    x = c(NA, 1, NA),
    y = c(NA, NA, "foo")
  )
  schema <- '{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "properties": {
    "x": {
      "type": "integer"
    },
    "y": {
      "type": "integer"
    }
  },
  "required": ["x", "y"]
}
'
  check_schema_df(dat, schema)
}

Sage-Bionetworks/dccvalidator documentation built on May 7, 2022, 10:32 a.m.