Indentation
In this lesson we will learn about indentation and spacing in R.
Line Length
The maximum line length is characters. This is the amount that will fit comfortably on a printed page at a reasonable size.
Indentation
When indenting your code, use two spaces.
Never use tabs or mix tabs and spaces.
Exception: When a line break occurs inside parentheses, align the wrapped line with the first character inside the parenthesis.
Spacing
- Place spaces around all binary operators (
=,+,-,<-, etc.).- Exception: Spaces around
='s are optional when passing parameters in a function call.
- Exception: Spaces around
- Do not place a space before a comma, but always place one after a comma.
- Place a space before left parenthesis, except in a function call.
- Extra spacing (i.e., more than one space in a row) is okay if it improves the alignment of equals signs
=or arrows<-.
- Do not place spaces around code in parentheses or square brackets.
- Exception: Always place a space after a comma.