The function transformIllegalChars
replaces characters that are typically considered illegal or
problematic in variable names—such as spaces, mathematical operators, or punctuation marks—with
descriptive placeholder tokens (e.g., .space.
, .comma.
). This is particularly useful for
variable names when exporting data, using variable names in formulas, or avoiding syntax errors.
The function supports two modes:
The argument except
allows specific characters or tokens to be exempted from transformation or
recovery. Additionally, after processing, the function checks whether all resulting values are
numeric and, if so, prepends "var_"
to preserve name validity.
This function uses an auxiliary function deleteIllegalChars()
to sanitize additional issues
before applying transformations.