Menu
Coddy logo textTech

Naming Conventions

Part of the Fundamentals section of Coddy's R journey — lesson 9 of 78.

R has specific rules for valid variable names. A variable name must start with a letter (a-z or A-Z), and can contain letters, numbers, periods (.), and underscores (_). However, it cannot start with a number or contain spaces.

Beyond the basic rules, following naming conventions makes your code much more readable and maintainable. Two popular styles are snake_case (using underscores between words like user_name) and camelCase (capitalizing the first letter of each word except the first, like userName). Choose one style and use it consistently throughout your code.

Most importantly, use descriptive names that clearly indicate what the variable contains. Instead of x or data1, use names like student_score or monthly_sales. This makes your code self-documenting and easier for others (and your future self) to understand.

Cheat sheet

Variable names in R must start with a letter (a-z or A-Z) and can contain letters, numbers, periods (.), and underscores (_). They cannot start with a number or contain spaces.

Common naming conventions:

  • snake_case: words separated by underscores, e.g., user_name
  • camelCase: first letter lowercase, subsequent words capitalized, e.g., userName

Use descriptive names that clearly indicate the variable's content, such as student_score or monthly_sales, rather than generic names like x or data1.

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals