Skip to contents

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 add_dependency()

Adds dependencies for a validation.

Usage

Validator$add_dependency(validation_name, conditions)

Arguments

validation_name

The name of the validation.

conditions

A list of conditions that must be met before running the validation.


Method setup_validator()

Configures the validator with the subset of validations to execute.

Usage

Validator$setup_validator(validation_config)

Arguments

validation_config

A list defining which validations to run and their dependencies.


Method run_validations()

Runs the specified validations on the provided contributors table.

Usage

Validator$run_validations(contributors_table)

Arguments

contributors_table

A dataframe containing contributor data.

Returns

A list of validation results.


Method should_run()

Determines whether a validation should be executed based on dependencies.

Usage

Validator$should_run(validation_name, contributors_table)

Arguments

validation_name

The validation function name.

contributors_table

The dataframe containing contributor data.

Returns

TRUE if the validation should run, FALSE otherwise.


Method clone()

The objects of this class are cloneable with this method.

Usage

Validator$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.