View source: R/goose_survey_tools.R
| goose_rename_columns | R Documentation |
Transforms long survey question text into short, meaningful variable names. Combines janitor::clean_names() functionality with intelligent abbreviation to create readable, consistent column names. Saves a mapping file for reference.
goose_rename_columns(
data,
max_length = 20,
style = c("snake_case", "camelCase", "SCREAMING_SNAKE"),
abbreviate = TRUE,
save_map = TRUE,
map_file = NULL,
preview_only = FALSE,
custom_dict = NULL
)
data |
A data frame with columns to rename (typically survey data) |
max_length |
Maximum length for new column names (default: 20) |
style |
Naming style: "snake_case" (default), "camelCase", "SCREAMING_SNAKE" |
abbreviate |
Logical, whether to use intelligent abbreviation (default: TRUE) |
save_map |
Logical, whether to save the name mapping (default: TRUE) |
map_file |
Path to save the mapping CSV file (auto-generated if NULL) |
preview_only |
Logical, if TRUE only shows proposed changes without applying (default: FALSE) |
custom_dict |
Named vector of custom abbreviations (e.g., c("satisfaction" = "sat")) |
The function performs intelligent renaming by:
Removing special characters and standardizing format (via clean_names)
Detecting common survey patterns (scales, demographics, etc.)
Creating meaningful abbreviations for long questions
Ensuring uniqueness of all column names
Saving a reference map for documentation
Common patterns detected:
Likert scales ("How satisfied...", "To what extent...")
Demographics ("What is your age", "Gender", etc.)
Yes/No questions
Multiple choice questions
Open-ended responses
If preview_only = FALSE: Data frame with renamed columns If preview_only = TRUE: Data frame showing the mapping
## Not run:
# Basic usage - rename survey columns
survey_clean <- goose_rename_columns(survey_data)
# Preview changes first
goose_rename_columns(survey_data, preview_only = TRUE)
# Use custom abbreviations
survey_clean <- goose_rename_columns(survey_data,
custom_dict = c(
"satisfaction" = "sat",
"recommendation" = "rec",
"likelihood" = "likely"
)
)
# Use camelCase instead of snake_case
survey_clean <- goose_rename_columns(survey_data, style = "camelCase")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.