Skip to contents

Enforces the econanalyzr schema:

  • First 9 required columns with exact names and expected low-level type & primary class: date (Date/double), date_period_text (character), value (numeric/double), data_element_text (character), data_measure_text (character), date_measure_text (character), data_transform_text (character), geo_entity_type_text (character), geo_entity_text (character).

  • Any number of optional columns may appear after the first 9.

  • The final column must be viz_type_text of type/class character.

Usage

check_econanalyzr_df(df, datetime_tz = "UTC")

Arguments

df

A data frame or tibble to validate.

datetime_tz

String timezone used when coercing POSIXct/POSIXlt to Date. Defaults to "UTC" for deterministic behavior across environments.

Value

The validated tibble (possibly reordered and/or with date/value coerced).

Details

If all required columns and viz_type_text are present but out of order, the function emits a warning and reorders the columns to: required 9 (in order) → optional(s) → viz_type_text.

Special handling of date:

  • Accepts base Date and subclasses. Subclasses are coerced to plain Date with a warning.

  • Accepts zoo::yearmon/zoo::yearqtr (if zoo is installed) and always coerces to Date at the start of the period (first day of the month/quarter) with a warning.

  • Accepts POSIXct/POSIXlt and coerces to Date (drop time) using datetime_tz.

Special handling of value:

  • Must be double; if numeric but not double (e.g., integer or other numeric class), the column is coerced to double with a warning. Non-numeric is an error.

To support yearmon/yearqtr, add zoo to Suggests. If a yearmon/yearqtr column is encountered and zoo is not installed, a classed error is raised with guidance.

Examples

# check_econanalyzr_df(valid_data)