Style Guide
Misc
- Packages
- {styler}- Formats your code according to the tidyverse style guide (or your custom style guide)
- {lintr} - Provides static code analysis for R. It checks for adherence to a given style, identifying syntax errors and possible semantic issues, then reports them to you so you can take action.
- {flint} - Detects and automatically fixes lints in R code. It is also very fast and compatible with many {lintr} rule
- Resources
- Video: Stop Making Spaghetti (Code) - Using {styler} and {lintr}
- Get your codebase lint-free forever with lintr
Naming
- Characteristics
- Good names are a form of documentation
- Nested loop variables should be names, not letters
- Names should be easily searchable
- Use prefixes and positive terms for booleans
- Add extra detail for test functions
- Names should be pronouncable
- Use consistent lexicon throughout a project
- Good names are a form of documentation
- Nested loop variables should be names, not letters
- Names should be easily searchable
- Use prefixes and positive terms for booleans
- Add extra detail for test functions
- Names should be pronouncable
- Use consistent lexicon throughout a project
Refactoring
Flatten nested code
- Condition on the negative