Style Guide
Misc
- Packages/Tools
- {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} rules
- {tergo} - Rust-built package that styles R code according to the ‘tidyverse’ style guide
- Tools
- Resources
- Tidyverse Style Guide
- Video: Stop Making Spaghetti (Code) - Using {styler} and {lintr}
- Get your codebase lint-free forever with lintr
- Video: Why you shouldn’t nest your code
- Shows you techniques for denesting if-statements
- A linter analyzes code to identify bugs, stylistic errors, performance boosting options, and potential issues, while a formatter automatically adjusts the code’s appearance to ensure consistent styling without changing its functionality.
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
.png)
- Nested loop variables should be names, not letters
.png)
- Names should be easily searchable
.png)
- Use prefixes and positive terms for booleans
.png)
- Add extra detail for test functions
.png)
- Names should be pronouncable
.png)
- Use consistent lexicon throughout a project
.1.png)
Refactoring
Flatten nested code
- Condition on the negative

