Explanation
Before working with data, it’s important to set up a clean and organized project directory. A consistent folder structure helps you manage scripts, datasets, and outputs across both Python and R — making your work easier to follow and share.
In this guide, we’ll create a root directory called general-data-science
with four folders:
data/
– for datasets
scripts/
– for code files
images/
– for plots and charts
library/
– for reusable functions
Example Folder Structure:
general-data-science/
├── data/
├── scripts/
├── images/
└── library/
Bash (Terminal)
You can create the entire structure using this single command:
mkdir -p general-data-science/{data,scripts,images,library}
cd general-data-science
Python Code
You can also create the same folder structure in Python:
import os
folders = ["data", "scripts", "images", "library"]
root = "general-data-science"
os.makedirs(root, exist_ok=True)
for folder in folders:
os.makedirs(os.path.join(root, folder), exist_ok=True)
print(f"Created '{root}' project folder with subdirectories.")
R Code
Here’s how to do it in R:
folders <- c("data", "scripts", "images", "library")
root <- "general-data-science"
if (!dir.exists(root)) dir.create(root)
for (folder in folders) {
dir.create(file.path(root, folder), showWarnings = FALSE)
}
cat("Created", root, "project folder with subdirectories.\n")