Analytical Coding Guide

This site provides the Cabinet Office Analysis & Insight team’s guide for coding in analytical projects.

The purpose of this guide is to provide simple advice about how to use code in our analysis. It is broken down into three sections: workflow, style and output. This site is a ‘living document’ that will evolve as our approach develops/changes. While the guide is intended to be language independent, given our practice examples are more likely to be based on using R or R Studio. Our approach to coding and analysis is particularly influenced by the Tidyverse.

This guide isn’t designed to provide a rulebook of ‘hard’ standards that must be followed, rather it provides advice and general guidelines to using code in analytical projects. There are many other guides and resources developed by others, which provide more detailed information and have influenced this guide to more o. Each person and team also have their own individual style and perferences - this guide is designed to provide some common building blocks so that it is easier for our analysts to work together when coding.


Our workflow guidelines set out how you should structure and manage code in an analytical project.

  1. Project-based working
  2. Scripting
  3. Functional programming
  4. Dependency management
  5. Version control (git)
  6. Documentation
  7. QA and code review


Our style guidelines set out how to write code for a project.

  1. Naming conventions
  2. Code Flow
  3. Syntax
  4. Pipe
  5. Comments and documentation
  6. Error messages


Our output guidelines set out some principles for presenting results.

  1. Tables
  2. Graphs
  3. Slide decks
  4. Publishing

This site was built using govdown.