ColumnValidator Class for Contributors Table
ColumnValidator Class for Contributors Table
Details
The ColumnValidator
class performs column-level validation for a contributors table.
It ensures that required columns exist, applying logical validation rules such as:
AND: All listed columns must be present.
OR: At least one of the listed columns must be present.
NOT: None of the listed columns should be present.
This validation process is configurable via a YAML file.
Regex Matching
Some columns may follow a dynamic naming pattern (e.g., "Affiliation 1", "Affiliation 2").
The regex
field in the YAML configuration allows pattern-based matching.
YAML Configuration
The validator reads a YAML file (e.g., inst/config/columnvalidator_example.yaml
) that defines:
Rules specifying required columns.
Operators (
AND
,OR
,NOT
) for column validation.Regex patterns for dynamically named columns.
Severity levels (
error
orwarning
).
Example:
column_config:
rules:
minimal:
operator: "AND"
columns:
- Firstname
- Middle name
- Surname
- Order in publication
severity: "error"
affiliation:
operator: "OR"
columns:
- Primary affiliation
- Secondary affiliation
regex: "^Affiliation [0-9]+$"
severity: "error"
title:
operator: "AND"
columns:
- Corresponding author?
- Email address
severity: "warning"
Integration with ValidateOutput
The ValidateOutput
class initializes an instance of ColumnValidator
to perform column checks.
If required columns are missing, the validation process halts, returning only column validation errors.
Usage
# Load a column validation config
config <- yaml::read_yaml("inst/config/columnvalidator_example.yaml")
# Create a ColumnValidator instance
column_validator <- ColumnValidator$new(config_input = config$column_config)
# Validate a contributors table
results <- column_validator$validate_columns(contributors_table)
See also
ValidateOutput
which integrates this class for validation.
Methods
Method check_rule()
Checks whether the contributors table satisfies a specific validation rule.