Skip to contents

One call after every import, before any model. Reports, per categorical column: storage, levels in order, counts, the reference level R would use, and flags for the known hazards — numeric-looking labels (the signature of codes imported from SPSS/Stata without their value labels), still-labelled foreign columns (haven_labelled), case-variant duplicate labels, unused levels, and high-cardinality accidents.

Usage

morie_audit_categories(data, cols = NULL)

Arguments

data

A data frame.

cols

Columns to audit (default: every factor/character/ labelled column).

Value

An object of class morie_category_audit: a data frame with one row per column (column, storage, n_levels, levels, reference, hazards) plus a clean attribute. Its print method shouts the hazards.

Examples

df <- data.frame(race = factor(c("1", "2", "2", "3")),
                 city = c("Toronto", "toronto", "Ottawa", "Ottawa"))
morie_audit_categories(df)
#> Categorical audit: 2 column(s)
#>   race             factor     3 level(s), reference ‘1’
#>     !! HAZARD: all labels numeric-looking (1,2,3...): likely imported CODES whose value labels were lost; as.numeric() on this column returns level INDICES, not data 
#>   city             character  3 level(s), reference ‘Ottawa’
#>     !! HAZARD: case-variant duplicate labels: ‘Toronto’, ‘toronto’