Validator Class for Contributors Table
Validator Class for Contributors Table
Details
The Validator
class runs a set of user-defined validation functions on
a contributors table. It allows for configuring which validations should
be executed, handling dependencies between validations, and storing results.
This class is used in conjunction with the ValidateOutput
class to
apply both column and general table validations.
Configurable Validations
The class dynamically loads validation functions, allowing users to add
custom checks. By default, the predefined functions in validate_helpers.R
are available.
Dependencies
Some validations depend on the presence of specific columns or successful execution of other validations. These dependencies are defined in a YAML config file.
YAML Configuration
The validator reads a YAML configuration file (e.g., inst/config/validator_example.yaml
),
which specifies:
The validations to run.
Any dependencies between them.
Example:
validation_config:
validations:
- name: check_missing_corresponding
dependencies:
- '"Corresponding author?"
- name: check_missing_email
dependencies:
- '"Corresponding author?"
- 'self$results[["check_missing_corresponding"]]$type == "success"'
- '"Email address"
Usage
# Create a Validator instance
validator <- Validator$new()
# Configure which validations should run
validator$setup_validator(validation_config)
# Run the validations on a contributors table
results <- validator$run_validations(contributors_table)
See also
ValidateOutput
which integrates this class for validation.
Public fields
validations
A list of validation functions dynamically loaded from
validate_helpers.R
or custom functions.dependencies
A list of validation dependencies.
results
Stores the results of executed validations.
specified_validations
The subset of validations to execute, defined in the YAML config.
Methods
Method new()
Initializes the Validator
class.
Loads predefined validations from validate_helpers.R
and allows for adding custom validations.
Usage
Validator$new()
Method should_run()
Determines whether a validation should be executed based on dependencies.