Skip to content

Coding principles

Tim Treis edited this page Mar 19, 2021 · 14 revisions

We wish the package to be easily used and integrated into then normal analysis and visualisation flow. This requires maximal compatibility with existing standard tools and packages. All new functions should thus preferably be built using the widely adapted tidyverse.

Data Manipulation

  • Data is expected to be present in tidy form (one row per observation) unless otherwise noted.
  • Ideally tibbles are used rather than dataframes.
  • The magrittr pipe (%>%) should be used for consecutive operations on the the data.
  • For models the broom package easily converts key information about the models into tidy data tibbles for subsequent wrangling and visualisation.

Figures

  • Plotting should be implemented using ggplot2 unless this is not possible.
  • Interactivity may be provided using ggplotly or - if needed plotly or other packages

Tables

  • Tables should always be also available as raw tibbles and output should not be only in formatted ways (e.g., only html, only markdown etc.)

Testing

  • Write tests as soon as the function is in a somewhat usable state. Improving is easier than starting.
  • Use vdiffr for comparison of anything plotted against a library of manually curated
  • Educate over break: Rather than just stopping if parameters have been provided that don't make sense, like shape = NULL, just warn the user that this doesn't make sense and set it to a reasonable default, the function's default if applicable. "But what if the user wanted to disable the shape that way?" -> Then just don't call the function to add it.