Fixes if a factor list does not have named levels or has special characters in the names
fix_name_labels(x, pattern = NA, replacement = ".")
the vector or list to fix
regex pattern to replace; defaults to non-word characters and the value of faux_options("sep") (default = _)
the character to replace; defaults to . (or _ if faux_options("sep") == ".")
a named list with fixed names
source <- list("full.stop", " space ", "under_score", "plus+", "dash-", "tab\t", "line\nbreak")
fix_name_labels(source)
#> $full.stop
#> [1] "full.stop"
#>
#> $.space.
#> [1] " space "
#>
#> $under.score
#> [1] "under_score"
#>
#> $plus.
#> [1] "plus+"
#>
#> $dash.
#> [1] "dash-"
#>
#> $tab.
#> [1] "tab\t"
#>
#> $line.break
#> [1] "line\nbreak"
#>