Thursday, April 30, 2020

R style guide

Style:

This is a big one! follow the tidyverse style guide: https://style.tidyverse.org/
Key things are:

  • naming conventions: use underscores, be concise and descriptive
  • lines should be max 80 characters wide
Something that they don't make clear enough is that there is a difference between commenting in code and documenting.

Think about it like the difference between the blurb at the top of a recipe (that explains what the dish is all about, its backstory, its history, the subtle nuance etc) and the individual steps themselves.

These look different in R:

  •  use "#" for comments, 
  • and " #' " for documentation. 
  • separate sections using comment blocks "# Section name ========" (80 lines wide)

Share this