One way to organize your R projects

21/09/2021 update: READ THIS: https://osf.io/j6yg9/

When I started to code in R, my projects were (very) messy, mixing both scripts, datasets, and report within the same folders. I then learn how to properly organize my projects during one of my internships. I present the ABC of the method in this post.

Of course, it can be modified according to your needs but I think it is a good starting point, especially if you are a beginner.

Why do you need to organize your projects?

Project organization mainly aims to ensure reproducibility and clarity, making it possible for others to understand what you did and to continue the project if needed.

The main philosophy behind the folder organization

The method that I present in this post mainly stands on two pillars:

  1. the project should be self-contained. For example, scripts should not contain any local pathway and the complete analysis, from raw data to report, could be run without any single change;

  2. files with the same nature should be stored within the same sub-folders.

The method

The method consists in organizing your project file as follow:

  1. 00_document: contains all the files related to the context of the project. It can be either document related to the dataset or related to the institution or theoretical context;

  2. 01_raw_data: contains all the raw datasets. They are the starting point from the analysis and should be stored as they had been downloaded or transferred. If there are several versions of the raw datasets, don't forget to indicate which one is the most recent (and hence relevant) ones;

  3. 02_clean_data: contains all the datasets (.RDS) produced throughout the analysis;

  4. 03_codes: contains all the R script;

  5. excel_output: if needed, this folder contains excel files produced during the analysis;

  6. figures_output: contains figures produced during the analysis, if needed;

  7. files_for_report: contains all the files used for the .Rmd knitting such as image, final R image, templates, etc.;

  8. project: R project files, making it possible to use non-local path;

  9. readme: a file with the description of the project folder and each sub-folders;

  10. report: RMD files to produce the full report from the analysis;

Additional posts on how to organize the 03_codes folder and setting up the .Rmd file are available in the website.

The steps to follow to create your project

  1. Open R studio, go to 'File'>'New project'>'New directory'>'New projects', then choose your name and location for the project and then click on 'Create project'

  2. Run the following codes in the console:

dir.create("00_document")
dir.create("
01_raw_data")
dir.create("
02_clean_data")
dir.create("
03_codes")
dir.create("
excel_output")
dir.create("figures_output")
dir.create("
files_for_project")

  1. Create the readme.txt in the folder

  2. Set up everything for the report (see the coming post)

  3. Start your analysis !

Be careful, every time you want to work on your project, open R Studio through the R project files.


An example can be downloaded here.