Learn R Programming

wizaRdry (version 0.6.4)

ValidationState: ValidationState R6 Class

Description

Manages NDA validation state and tracks modifications to data structures. Central object for tracking validation results, modifications, and determining whether data definition files need to be created.

Arguments

Public fields

measure_name

Character - name of the measure/structure

api

Character - API type (redcap, qualtrics, mongo, etc.)

data_env

DataEnvironment - manages dataframe across environments

nda_structure

List - NDA structure definition from API

is_valid

Logical - whether validation passed

is_new_structure

Logical - whether structure is new (not in NDA)

is_modified_structure

Logical - whether existing structure has modifications

bypassed_validation

Logical - whether validation was bypassed (new structures)

value_range_violations

List - fields with value range violations

new_fields

Character vector - fields in data not in NDA structure

ndar_subject_additions

Character vector - DCC fields added from ndar_subject01

ndar_subject01_all_fields

Character vector - ALL field names from ndar_subject01 (~150 fields) Used for consistent formatting in Excel exports regardless of dcc parameter

renamed_fields

Character vector - fields that were renamed

dropped_fields

Character vector - fields that were dropped

missing_required

Character vector - required fields with missing data

required_metadata

Data frame - ndar_subject01 required field metadata

recommended_metadata

Data frame - ndar_subject01 recommended field metadata

warnings

Character vector - warning messages

errors

Character vector - error messages

dcc

Logical - whether DCC fields should be validated

Methods


Method new()

Create a new ValidationState instance

Usage

ValidationState$new(measure_name, api, df, nda_structure = NULL, dcc = FALSE)

Arguments

measure_name

Name of the measure/structure

api

API type (redcap, qualtrics, mongo, csv, oracle, sql)

df

Initial dataframe

nda_structure

NDA structure definition (NULL for new structures)

dcc

Logical - whether DCC fields should be validated

Returns

A new ValidationState object


Method get_df()

Get current dataframe

Usage

ValidationState$get_df()

Returns

Data frame


Method set_df()

Update dataframe in all environments

Usage

ValidationState$set_df(df)

Arguments

df

New dataframe

Returns

Self (invisibly) for method chaining


Method add_value_range_violation()

Add a value range violation

Usage

ValidationState$add_value_range_violation(field, expected, actual)

Arguments

field

Field name

expected

Expected value range (NULL if no range defined)

actual

Vector of violating values

Returns

Self (invisibly) for method chaining


Method add_violations()

Add violations of a specific type (e.g., DCC violations)

Usage

ValidationState$add_violations(type, violations)

Arguments

type

Character - type of violations ("dcc_required", "dcc_recommended", etc.)

violations

List - violations to add

Returns

Self (invisibly) for method chaining


Method set_valid()

Set validation status

Usage

ValidationState$set_valid(valid)

Arguments

valid

Logical - TRUE if validation passed, FALSE otherwise

Returns

Self (invisibly) for method chaining


Method has_modifications()

Check if structure has modifications requiring data definition

Usage

ValidationState$has_modifications()

Returns

Logical


Method needs_data_definition()

Determine if data definition file is needed

Usage

ValidationState$needs_data_definition()

Returns

Logical - TRUE if data definition should be created


Method get_modification_reason()

Get human-readable modification reason

Usage

ValidationState$get_modification_reason()

Returns

Character string describing why structure is modified


Method to_list()

Convert to list for backward compatibility with old validation_results

Usage

ValidationState$to_list()

Returns

List with validation results


Method print()

Print method for ValidationState

Usage

ValidationState$print()

Returns

Self (invisibly)


Method clone()

The objects of this class are cloneable with this method.

Usage

ValidationState$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

This class replaces the fragile attribute-passing pattern used previously. It provides a structured way to track:

  • Validation status (valid/invalid, new/existing structure)

  • Value range violations

  • New fields added

  • Required field status

  • Metadata from ndar_subject01

The key method needs_data_definition() determines whether a data definition file should be created based on whether the structure is new or modified.