
Get expected target data column names from config
Source:R/utils-target_data.R
get_target_data_colnames.RdExtracts the expected column names for target data from a hub's configuration files in the correct order. This is useful for validation and schema generation without needing to inspect the actual dataset.
Usage
get_target_data_colnames(
config_target_data,
target_type = c("time-series", "oracle-output")
)Value
A character vector of expected column names in the correct order:
Date column
Task ID columns (from
observable_unit)Non-task ID columns (time-series only, if specified in config)
Output type columns (
output_typeandoutput_type_id, oracle-output only if specified in config)Target value column (
observationfor time-series,oracle_valuefor oracle-output)as_ofcolumn (if data is versioned)
Details
The function builds the column name vector directly from the configuration objects without requiring dataset inspection. This makes it lightweight, efficient, and suitable for validation purposes.
For time-series data, columns are ordered as:
Task ID columns from
observable_unitDate column (if not in
observable_unit)Non-task ID columns from
target-data.json(if present)observationcolumn (target value)as_ofcolumn (ifversioned = TRUE)
For oracle-output data, columns are ordered as:
Task ID columns from
observable_unitDate column (if not in
observable_unit)output_typeandoutput_type_idcolumns (ifhas_output_type_ids = TRUE)oracle_valuecolumn (target value)as_ofcolumn (ifversioned = TRUE)
Examples
# Note: These examples require test data
hub_path <- system.file("testhubs/v6/target_file", package = "hubUtils")
config_target_data <- hubUtils::read_config(hub_path, "target-data")
# Get time-series column names
get_target_data_colnames(
config_target_data,
target_type = "time-series"
)
#> [1] "target_end_date" "target" "location" "observation"
# Get oracle-output column names
get_target_data_colnames(
config_target_data,
target_type = "oracle-output"
)
#> [1] "target_end_date" "target" "location" "output_type"
#> [5] "output_type_id" "oracle_value"