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, evaluating
context-aware conditions, and storing results.
This class is used in conjunction with the ValidateOutput class to
apply both column-level and data-level validation.
Configurable Validations
The class loads validation functions explicitly, ensuring they are available
in all environments. By default, the predefined functions in validate_helpers.R
are loaded.
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 and evaluated dynamically during runtime.
Context-Aware Validation
The validator supports an optional context parameter, which can hold additional information about the environment in which validation is run.
This allows validation logic and dependency conditions to react to dynamic
UI states or user selections (e.g., "include" = "author", "order" = "desc").
The context object is a named list accessible inside dependencies and
validation functions, enabling conditional validation rules.
Example use cases:
Running separate validations for authors vs. acknowledgees.
Changing which checks run depending on toggle inputs in a Shiny app.
Adjusting severity or skipping certain checks dynamically.
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"
- name: check_subset_specific_rule
dependencies:
- 'context$include == "author"'
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 with optional context
context <- list(include = "author", order_by = "desc")
results <- validator$run_validations(contributors_table, context = context)
# Access validation results
print(results)Notes
If no
contextis provided, all validations run as before (backward-compatible).Validation helpers can optionally define a
contextargument to access contextual data.Within YAML dependency conditions, the
contextobject is automatically available.
See also
ValidateOutput— integrates theValidatorandColumnValidatorclasses.ColumnValidator— ensures required columns exist before data validations.
Public fields
validationsA list of validation functions explicitly loaded from
validate_helpers.Ror custom functions.dependenciesA list of validation dependencies.
resultsStores the results of executed validations.
specified_validationsThe subset of validations to execute, defined in the YAML config.
contexthold runtime context parameters (UI/state toggles etc.)
Methods
Method new()
Initializes the Validator class.
Loads validation functions explicitly from validate_helpers.R and allows for adding custom validations.
Usage
Validator$new()Method load_validation_functions()
Loads validation functions explicitly. This ensures all validation functions are available in all environments.
Method run_validations()
Runs the specified validations on the provided contributors table.
Method should_run()
Determines whether a validation should be executed based on dependencies.
