3  Organising Codes and Files

It is vital to have an efficient organisation for your codes and related folders.

As you accumulate a significant amount of code files, it is essential to keep them well-organised to avoid getting lost.

Ideally, you would want to be able to go back to a code 5 years from now and be able to find the code file, and to understand what you have written in this code.

This is particularly important if you need to go back to some analysis you have previously conducted.


Flooding Workflow

Flowing Workflow

Three steps towards an efficient workflow

There are three primary things you can do to set up an efficient structure:

  1. Having a coherent folder structure
  2. Having clear file names
  3. Annotating your code

Create a Coherent Folder Structure

The first step towards organising your codes and files is to create a coherent folder structure. It is important to organise your work into separate folders and subfolders.

Let’s take the example of your Bachelor’s degree studies. One effective approach to organise your studies would be to create first a main folder (for your degree program), and within that folder, create sub-folders for each year of study.

Within each year folder, you can further categorise your materials by creating sub-folders for each class you are taking. Within each class folder, you could create additional sub-folders to store different components of your coursework. For example, you might have folders labelled “Assignments,” “Lecture Notes,” “R Scripts” and so on.

By employing a hierarchical folder structure, you can easily locate and access specific materials.

flowchart LR
  A[Folder: BA Sociology] --> Y1[Folder: Year 1]
  A[Folder: BA Sociology] --> Y2[Folder: Year 2]
  Y1 --> D1[Folder: SC 101] 
  D1 --> X1[Folder: Lecture Notes]
  D1 --> X2[Folder: R Scripts]

  Y1 --> D2[Folder: SC 102]
  D2 --> X3[Folder: Lecture Notes]
  D2 --> X4[Folder: R Scripts]
  
  Y2 --> D3[Folder: SC 201]
  Y2 --> D4[Folder: SC 202]

Consistent File Naming Conventions

A practical naming convention for saving code is to start with the date in the format Year-Month-Day. Then, include the name of the project and provide a brief description of what the code is doing.

For example, if I wrote code to clean data for a childcare project on February 17, 2023, I would name the code file as follows:

Comment and Document your Code

Adding comments and documentation to your code is essential for maintaining clarity, especially when revisiting a code after some time. Indentation and clear formatting also go a long way in enhancing the readability of a code.

Compare the readability of the two codes below


Code with no annotations


Code with annotations and formatting


Codes will never be completely clean but adding short comments and a small amount of formatting can help a lot.

Remember that organising your code is an ongoing process, and it can take time to find a workflow that works for you.