.to_factor_safely: Safely Convert Character Vectors to Factors
Description
An internal helper function that converts a character vector to a factor,
ensuring the level order is based on the first appearance of each element.
If the input is not a character vector, it's returned unchanged.
Usage
.to_factor_safely(x)
Value
A factor with levels in order of appearance, or the original object.