This function verifies the consistency between downloaded Comex data and the corresponding conference files provided by the official source (MDIC). It checks if the aggregated totals for specific columns match between the two sources.
Arguments
- years
A numeric vector specifying the years to check. If
NULL
(default), all available years are checked.- directions
A character vector specifying the directions of trade to check: 'imp' (imports) and/or 'exp' (exports). If
NULL
(default), both directions are checked.- type
A character string indicating the type of Comex data: 'ncm' (Nomenclatura Comum do Mercosul) or 'hs4' (Harmonized System 4-digit). Defaults to 'ncm'.
Value
No direct return value. The function prints a message indicating whether the check passed ('All clear!') or if there are mismatches between the data and conference files. If mismatches are found, a table displaying the discrepancies is printed and an error is raised.
Details
This function performs the following checks:
Input Validation: Ensures that the
type
argument is valid ('ncm' or 'hs4') and has a length of 1.Data Retrieval: Reads the relevant Comex data (based on the
type
) and the corresponding conference files.Filtering: Filters the data and conference files based on the specified
years
anddirections
if provided.Aggregation: Aggregates the Comex data by
year
anddirection
and calculates sums for relevant columns.Comparison: Compares the aggregated sums from the Comex data with the totals in the conference files.
Mismatch Reporting: If any mismatches are found, a table highlighting the differences is printed to the console.
Error Handling: If mismatches exist, the function raises an error to stop further analysis.