Parse variableStart field to extract raw variable name
Source:R/mockdata-parsers.R
parse_variable_start.RdThis function parses the variableStart field from variable_details metadata
and extracts the raw variable name for a specific database/cycle. It supports
recodeflow-standard formats: database-prefixed ("database::varname"),
bracket ("[varname]"), mixed, and plain formats.
Details
The function implements recodeflow-standard parsing strategies:
Database-prefixed format:
"database::varname"- for database-specific namesBracket format (whole string):
"[varname]"- for database-agnostic namesBracket format (segment):
"database1::var1, [var2]"-[var2]is DEFAULT for other databasesPlain format:
"varname"- uses value as-is
Important: [variable] represents the DEFAULT for all databases not explicitly
referenced with database:: notation. This reduces repetition when only one or a
few databases use different variable names.
For DerivedVar format, returns NULL (requires custom derivation logic).
See also
Other parsing-utilities:
parse_range_notation()
Examples
# Database-prefixed format
parse_variable_start("cycle1::height, cycle2::HEIGHT", "cycle1")
#> [1] "height"
# Returns: "height"
# Bracket format (database-agnostic)
parse_variable_start("[gen_015]", "cycle1")
#> [1] "gen_015"
# Returns: "gen_015"
# Mixed format - [variable] is DEFAULT for databases not explicitly listed
parse_variable_start("cycle1::amsdmva1, [ammdmva1]", "cycle2")
#> [1] "ammdmva1"
# Returns: "ammdmva1" (uses default for cycle2)
# Plain format
parse_variable_start("bmi", "cycle1")
#> [1] "bmi"
# Returns: "bmi"
# No match for specified database
parse_variable_start("cycle2::age", "cycle1")
#> NULL
# Returns: NULL