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:
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;
files with the same nature should be stored within the same sub-folders.
The method consists in organizing your project file as follow:
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;
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;
02_clean_data: contains all the datasets (.RDS) produced throughout the analysis;
03_codes: contains all the R script;
excel_output: if needed, this folder contains excel files produced during the analysis;
figures_output: contains figures produced during the analysis, if needed;
files_for_report: contains all the files used for the .Rmd knitting such as image, final R image, templates, etc.;
project: R project files, making it possible to use non-local path;
readme: a file with the description of the project folder and each sub-folders;
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
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'
Run the following codes in the console:
Create the readme.txt in the folder
Set up everything for the report (see the coming post)
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.