goose_rename_columns: Intelligently Rename Survey Columns

View source: R/goose_survey_tools.R

goose_rename_columnsR Documentation

Intelligently Rename Survey Columns

Description

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.

Usage

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
)

Arguments

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"))

Details

The function performs intelligent renaming by:

  1. Removing special characters and standardizing format (via clean_names)

  2. Detecting common survey patterns (scales, demographics, etc.)

  3. Creating meaningful abbreviations for long questions

  4. Ensuring uniqueness of all column names

  5. 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

Value

If preview_only = FALSE: Data frame with renamed columns If preview_only = TRUE: Data frame showing the mapping

Examples

## 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)

gooseR documentation built on Feb. 6, 2026, 5:07 p.m.