Skip to contents

[Stable]

Check if the data and spec are compatible by comparing the data.frames and columns in the spec with the data.

Usage

CheckSpec(lData, lSpec)

Arguments

lData

A list of data.frames.

lSpec

A list specifying the expected structure of the data.

Value

This function does not return any value. It either prints a message indicating that all data.frames and columns in the spec are present in the data, or throws an error if any data.frame or column is missing.

Examples

lData <- list(reporting_groups = gsm::reportingGroups, reporting_results = gsm::reportingResults)
lSpec <- list(
  reporting_groups = list(
    GroupID = list(required = TRUE),
    GroupLevel = list(required = TRUE),
    Param = list(required = TRUE),
    Value = list(required = TRUE)
  ),
  reporting_results = list(
    GroupID = list(required = TRUE),
    GroupLevel = list(required = TRUE),
    Numerator = list(required = TRUE),
    Denominator = list(required = TRUE)
  )
)
CheckSpec(lData, lSpec) # Prints message that everything is found
#> → All 2 data.frame(s) in the spec are present in the data: reporting_groups and reporting_results
#> → All specified columns in reporting_groups are in the expected format
#> → All specified columns in reporting_results are in the expected format
#> → All 8 required columns in the spec are present in the data: reporting_groups$GroupID, reporting_groups$GroupLevel, reporting_groups$Param, reporting_groups$Value, reporting_results$GroupID, reporting_results$GroupLevel, reporting_results$Numerator, and reporting_results$Denominator

lSpec$reporting_groups$NotACol <- list(required = TRUE)
CheckSpec(lData, lSpec) # Throws error that NotACol is missing
#> → All 2 data.frame(s) in the spec are present in the data: reporting_groups and reporting_results
#> → All specified columns in reporting_groups are in the expected format
#> → All specified columns in reporting_results are in the expected format
#>  Not all required columns in the spec are present in the data, missing columns are: reporting_groups$NotACol