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_namecamelCase: 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.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators (AND, OR)Logical Operators Part 2 (NOT)Recap - Simple LogicVectorized Logic Part 1Vectorized Logic Part 22Variables and Data Types
Numeric Data TypeInteger Data TypeCharacter Data TypeLogical Data TypeChecking Data TypesNaming ConventionsMissing Values: NARecap - Variable Creation8Loops
For LoopWhile LoopBreakNext (Continue)Recap - FactorialSequence Generation (seq, :)Nested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsInteger Division and ModuloAssignment OperatorsRecap - Simple MathComparison Operators6Basic IO
Print OutputCat for OutputOutput With VariablesReading Input with readline()Type Conversion BasicsRecap - Age CalculatorRecap - True or False9Functions
Declaring a FunctionFunction ArgumentsReturn ValuesRecap - Sigma FunctionRecap - Validation FunctionDefault Parameter Values