R Comments

R Comments
They are ignored by R during execution.
1. Single-Line Comment (#)
R supports single-line comments using the # symbol.
Anything after # on the same line is treated as a comment.
2. Multiple-Line Comments
R does not have a special multi-line comment syntax.
Instead, use # at the beginning of each line.
3. Commenting Out Code (Disable Code)
Comments are often used to temporarily stop code execution.
- Useful for debugging
4. Comments Inside Functions
5. Best Practices for Comments
- Write comments to explain why, not just what
- Keep comments short and clear
- Avoid unnecessary comments
- Update comments when code changes
6. Bad vs Good Comments
Bad:
Good:
7. Keyboard Shortcut (RStudio)
Windows / Linux:
Ctrl + Shift + CMac:
Cmd + Shift + C
Quickly comment or uncomment selected lines
Summary
#is used for commentsR supports single-line comment only
Comments improve code readability
Not executed by R
