Skip to content

Coding principles

Steven Haesendonckx edited this page Apr 19, 2022 · 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 preferably be built using the widely adapted tidyverse (please see namespace for allowed package dependencies). Dependencies should be kept to a minimum.

Data Manipulation

  • Data is expected to be present in tidy form (one row per observation) unless otherwise noted.
  • Ideally dataframes are used rather than tibbles.
  • The magrittr pipe (%>%) can 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. Note that the implemented methods are lazy and only extract key information, used in most common downstream processing. visR has custom tidiers that extract the informtation from model objects into a dataframe so users have all the information required for any downstream processing.

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

Style

  • CRAN requires us to use TRUE/FALSE, so don't use T/F.
  • Subset using '[[' rather than '$' to avoid surprises with partial matching

Tables

  • Tables should always be also available as raw dataframes 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.
  • Add a new test for every issue/bug that is identified
  • Use vdiffr for comparison of anything plotted against a library of manually curated plots.
  • Educate over break: Rather than just stopping if parameters have been provided that don't make sense, like shape = NULL, warn the user that this a required argument and set it to a reasonable default.

Package maintenance

We have integrated several "watchdogs" into our testing routine to ensure adherence to certain standards that we've set. Those routines scan our codebase for possible style violations:

1) CRAN watchdog

For a successful submission to CRAN, certain rules have been set in place by the CRAN team, as for example the usage of TRUE/FALSE over T/F. To continuously ensure compliance with those, our CRAN watchdog scans the respective files for violations of those.

2) Validation watchdog (in PR)

We want to make it easy to use our package in a more stringent environment that might require all packages to be validated. Based on discussions and similar projects we decided to implement traceability into our testing files. Therefore, both the tests as well as the last change to those, are automatically written into the files for potential scraping. The details on the last change are gathered by usage of git log and then table of contents for the unit test specifications are generated based off of the strings in the actual tests.