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
    • Air - A R formatter and language server, written in Rust.
    • Jarl - A fast linter for R: it does static code analysis to search for programming errors, bugs, and suspicious patterns of code.
  • Resources
  • 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
  • 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

    Nested

    Nested

    Flattened

    Flattened

    • Condition on the negative