
Infer column types after cleaning, then optionally layer factor detection
Source:R/utils.R
auto_parse_types.RdPOLIS returns every field as character. This parses character columns to
their natural base type (numeric, integer, date, datetime, logical) via
readr::type_convert(), protecting identifier-like names and leading-zero
codes from coercion, and optionally proposes low-cardinality character
columns as factors. The cleaners (clean_afp() etc.) call it with
apply = FALSE (base types only) when polis_config(parse_types = TRUE).
Arguments
- data
A data frame or tibble.
- max_levels
Maximum distinct values for a factor candidate. Default 50.
- max_unique_ratio
Maximum unique/non-NA ratio for a factor. Default
0.2.- protect_patterns
Regexes for names kept as character. Default
c("id$", "uid$", "code$", "ref$", "key$").- keep_leading_zero_chars
Keep a character column when any value is a leading-zero digit string (e.g.
"00123"). DefaultTRUE.- apply
If
TRUE(default) apply factor conversions on top of the parsed base types; ifFALSEparse base types only.- return
One of
"data","both","plan". Default"data".