Skip to contents

Reads a column name written by [csfmt_var] back into its parts. It strips the trailing coordinates, then a role, then a `_vs_<denom>` segment, and whatever is left is the measure.

Usage

csfmt_parse(varname)

Arguments

varname

Character scalar column name.

Value

Named list with the components that were present (e.g. `measure`, `role`, `q`, `denom`, `per`).

Where it does not invert csfmt_var

The parse is a right-to-left strip against a fixed role vocabulary, so it cannot tell which of several role-looking segments was the role. On the package's own rate name it gets the denominator wrong:


csfmt_var("numerator_nowcasted", denom = "denominator_nowcasted", per = 100)
#> "numerator_nowcasted_vs_denominator_nowcasted_pr100"
csfmt_parse("numerator_nowcasted_vs_denominator_nowcasted_pr100")$denom
#> "denominator"          # the denominator's own "_nowcasted" was eaten as the role

Treat it as reliable for a single-role name such as `numerator_nowcasted_q50x0`. Check the result whenever the measure or the denominator itself ends in a role word.

See also

[csfmt_var] writes these names. vignette("pipeline", package = "csalert"), whose closing section parses a collapsed median column with this function.

Other naming grammar functions: csfmt_interpret(), csfmt_var(), q_label(), q_value()

Examples

csfmt_parse("numerator_nowcasted_q50x0")
#> $measure
#> [1] "numerator"
#> 
#> $role
#> [1] "nowcasted"
#> 
#> $q
#> [1] 0.5
#> 

# the documented limit: a denominator that itself ends in a role word is
# truncated, because the role is stripped before the _vs_ segment is read
csfmt_parse("numerator_nowcasted_vs_denominator_nowcasted_pr100")
#> $measure
#> [1] "numerator_nowcasted"
#> 
#> $denom
#> [1] "denominator"
#> 
#> $role
#> [1] "nowcasted"
#> 
#> $per
#> [1] 100
#>