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.
measure_nameCharacter - name of the measure/structure
apiCharacter - API type (redcap, qualtrics, mongo, etc.)
data_envDataEnvironment - manages dataframe across environments
nda_structureList - NDA structure definition from API
is_validLogical - whether validation passed
is_new_structureLogical - whether structure is new (not in NDA)
is_modified_structureLogical - whether existing structure has modifications
bypassed_validationLogical - whether validation was bypassed (new structures)
value_range_violationsList - fields with value range violations
new_fieldsCharacter vector - fields in data not in NDA structure
ndar_subject_additionsCharacter vector - DCC fields added from ndar_subject01
ndar_subject01_all_fieldsCharacter vector - ALL field names from ndar_subject01 (~150 fields) Used for consistent formatting in Excel exports regardless of dcc parameter
renamed_fieldsCharacter vector - fields that were renamed
dropped_fieldsCharacter vector - fields that were dropped
missing_requiredCharacter vector - required fields with missing data
required_metadataData frame - ndar_subject01 required field metadata
recommended_metadataData frame - ndar_subject01 recommended field metadata
warningsCharacter vector - warning messages
errorsCharacter vector - error messages
dccLogical - whether DCC fields should be validated
new()Create a new ValidationState instance
ValidationState$new(measure_name, api, df, nda_structure = NULL, dcc = FALSE)measure_nameName of the measure/structure
apiAPI type (redcap, qualtrics, mongo, csv, oracle, sql)
dfInitial dataframe
nda_structureNDA structure definition (NULL for new structures)
dccLogical - whether DCC fields should be validated
A new ValidationState object
get_df()Get current dataframe
ValidationState$get_df()Data frame
set_df()Update dataframe in all environments
ValidationState$set_df(df)dfNew dataframe
Self (invisibly) for method chaining
add_value_range_violation()Add a value range violation
ValidationState$add_value_range_violation(field, expected, actual)fieldField name
expectedExpected value range (NULL if no range defined)
actualVector of violating values
Self (invisibly) for method chaining
add_violations()Add violations of a specific type (e.g., DCC violations)
ValidationState$add_violations(type, violations)typeCharacter - type of violations ("dcc_required", "dcc_recommended", etc.)
violationsList - violations to add
Self (invisibly) for method chaining
set_valid()Set validation status
ValidationState$set_valid(valid)validLogical - TRUE if validation passed, FALSE otherwise
Self (invisibly) for method chaining
has_modifications()Check if structure has modifications requiring data definition
ValidationState$has_modifications()Logical
needs_data_definition()Determine if data definition file is needed
ValidationState$needs_data_definition()Logical - TRUE if data definition should be created
get_modification_reason()Get human-readable modification reason
ValidationState$get_modification_reason()Character string describing why structure is modified
to_list()Convert to list for backward compatibility with old validation_results
ValidationState$to_list()List with validation results
Self (invisibly)
clone()The objects of this class are cloneable with this method.
ValidationState$clone(deep = FALSE)deepWhether to make a deep clone.
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.