graph TD
A[Edit Files] --> B[Stage]
B --> C[Commit]
C --> D{Collaborating?}
D -->|Yes| E[Pull First]
D -->|No| F[Push]
E --> F
F --> A
RStudio, Projects, and Version Control with Git
Organised by the SDPI D4D Program
2026-08-30
R is purpose-built for statistical computing
Strengths:
Perfect for:
Different tools for different jobs:
| Language | Best For | Speed | Learning Curve |
|---|---|---|---|
| R | Statistics, data science, visualization | Moderate | Gentle |
| Python | General programming, ML, automation | Fast | Gentle |
| Julia | High-performance computing | Very Fast | Moderate |
| Stata | Economics, panel data | Moderate | Gentle |
| MATLAB | Engineering, simulations | Fast | Moderate |
Pro Tip
Most researchers use multiple tools. R excels at statistical analysis and creating publication-quality figures.
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(aes(color = factor(cyl)),
size = 3, alpha = 0.7) +
geom_smooth(method = "lm",
se = FALSE,
color = "darkblue") +
labs(title = "Car Weight vs. Fuel Efficiency",
x = "Weight (1000 lbs)",
y = "Miles per Gallon",
color = "Cylinders") +
theme_minimal(base_size = 12)
IDE = Integrated Development Environment
An IDE brings together all the tools you need:
The Traditional Choice
Best for: - Pure R projects - R package development - Teaching R - Traditional workflows
The Modern Alternative
Best for: - Multi-language projects (R + Python) - Users familiar with VS Code - Modern development workflows - Those wanting cutting-edge features
For This Course
We’ll primarily use RStudio for demos, but everything works in Positron too! Choose what feels comfortable.
Four Main Panes:
Note
You can customize pane layout in Tools > Global Options > Pane Layout
Want to try the new IDE?
Download:
Key Features:
Interface:
Ctrl/Cmd + Shift + P)Status:
Recommendation
Stick with RStudio for learning, explore Positron once comfortable. Both are excellent!
Recommendation
Stick with RStudio for learning, explore Positron once comfortable. Both are excellent!
| Feature | RStudio | Positron |
|---|---|---|
| Maturity | Stable (10+ years) | Beta (2024+) |
| Languages | Primarily R | R + Python + more |
| Learning Curve | Gentle | Gentle (familiar if you know VS Code) |
| R Package Dev | Excellent tools | Good, improving |
| Extensions | R-specific | VS Code marketplace |
| Performance | Good | Faster |
| Community | Large, established | Growing |
| Documentation | Extensive | Developing |
| Best Use Case | Pure R projects | Multi-language projects |
Note
Both are made by Posit (formerly RStudio Inc.) and both are free! Your choice depends on your workflow and preferences.
Keyboard Shortcuts (save your wrists!)
| Action | Windows/Linux | Mac |
|---|---|---|
| Run current line | Ctrl + Enter |
Cmd + Enter |
Assignment operator <- |
Alt + - |
Option + - |
Pipe operator %>% |
Ctrl + Shift + M |
Cmd + Shift + M |
| Comment/uncomment | Ctrl + Shift + C |
Cmd + Shift + C |
Tip
Type Alt + Shift + K (Windows) or Option + Shift + K (Mac) to see all shortcuts
.R)Use for:
Reproducible Research Made Easy
Important
YAML header (between ---) controls document metadata and output format
R Projects solve path problems
When you open an .Rproj file:
RStudio starts fresh R session
Working directory automatically set to project folder
Use relative paths that work anywhere:
Project-specific settings saved
Easy to zip and share entire project
Three common ways:
File > New Project > New DirectoryFile > New Project > Existing DirectoryFile > New Project > Version Control > GitRecommended structure:
my-project/
├── my-project.Rproj
├── README.md
├── data/
│ ├── raw/
│ └── processed/
├── scripts/
│ ├── 01-clean-data.R
│ └── 02-analyze.R
├── documents/
│ └── paper.qmd
├── figures/
└── output/
Pro Tips
Workshop Schedule Note
Today we’re introducing Git/GitHub concepts and basic setup. We’ll do a deep dive into Git workflows on Day 2/3 of the workshop with hands-on practice and advanced techniques.
Track every change to your project over time
Without version control:
thesis_final.docx
thesis_final_v2.docx
thesis_final_FINAL.docx
thesis_final_FINAL_revised.docx
thesis_final_actual_final.docx
😱 Which one is current?
😱 What changed between versions?
😱 Who made what changes?
With version control:
thesis.docx
✅ Complete history saved
✅ See all changes
✅ Revert to any version
✅ Multiple people can work
✅ Track who did what
Git = Distributed Version Control System
Note
Git is powerful but has a learning curve. We’ll focus on essential operations.
Tip
Think of Git as your local diary, GitHub as publishing that diary online
First time only:
Note
Use the same email as your GitHub account!
On GitHub:
Important
Initialize with README so repository isn’t empty
In RStudio:
File > New Project > Version Control > GitYou now have:
Today: Overview Only
We’re covering Git fundamentals today. Day 2/3 will include:
For now, focus on understanding the concepts!
Select which changes to save
Save staged changes with message
Download changes from GitHub
Upload your commits to GitHub
graph TD
A[Edit Files] --> B[Stage]
B --> C[Commit]
C --> D{Collaborating?}
D -->|Yes| E[Pull First]
D -->|No| F[Push]
E --> F
F --> A
Edit your files as normal
Click checkboxes next to changed files in Git pane
Click “Commit”, write message:
Add linear regression analysis
- Import survey data
- Run treatment effect model
- TODO: Add control variables
Click “Push” to sync with GitHub
update
fixed stuff
asdf
final version
changes
more changes
Problems:
Add regression models for main analysis
Fix missing data handling in cleaning script
Update Figure 2 with reviewer comments
Remove deprecated ggplot2 syntax
Why better:
In the Git pane you can:
Tip
Keep the Git pane open while working
Always: Stage → Commit → Pull → Push
Never skip the commit before pulling!
Why this order?
What causes conflicts?
Two people edit the same lines in the same file
Example scenario:
You: Edit line 10 of analysis.R, commit
Collaborator: Edit line 10 of analysis.R, push to GitHub
You: Try to push → Conflict!
You: Pull → Git says “fix conflicts”
You: Open file, see conflict markers:
You: Choose which to keep (or combine), save, commit, push
Branches let you work on features independently
gitGraph commit commit branch feature checkout feature commit commit checkout main commit merge feature commit
main branch = stable versionFor private repositories:
For public repositories:
Good practices:
✅ Communicate about who’s working on what
✅ Pull before starting work
✅ Commit small, logical changes
✅ Push regularly
✅ Write clear commit messages
✅ Review each other’s code
✅ Use branches for big changes
Avoid:
❌ Both editing same file simultaneously
❌ Committing large files (>100MB)
❌ Waiting days between pushes
❌ Vague commit messages
❌ Pushing broken code to main
❌ Force pushing (unless you know why)
You’re collaborating with future you
Tip
Start with private repos until comfortable, then make research public
Use a branch!
experimental-analysisYou preserved the working main branch
Lesson learned: Pull → Commit → Push
Prevention:
.gitignore fileIf you did commit:
Tell Git to ignore certain files:
# R files
.Rproj.user
.Rhistory
.RData
.Ruserdata
# Large data
data/raw/*.csv
data/raw/*.dta
# Outputs (regenerate from code)
figures/*.png
output/*.html
# System files
.DS_Store
Thumbs.db
# Sensitive
config/passwords.txt
.env
Tip
Every R project should have a .gitignore file
Issues
Pull Requests
Releases
GitHub Pages
GitHub Limits
Solutions:
RStudio GUI covers 90% of needs, but CLI is powerful:
Note
Learn CLI gradually as you need advanced features
R Projects
✅ Always use R Projects
✅ Use relative paths
✅ Never use setwd()
✅ Organize files logically
✅ Document in README
Git Commits
✅ Commit often
✅ Write descriptive messages
✅ Commit logical units
✅ Pull before pushing
✅ Don’t commit generated files
Collaboration
✅ Communicate clearly
✅ Use branches for features
✅ Review code together
✅ Resolve conflicts promptly
✅ Keep main branch stable
Reproducibility
✅ Document dependencies
✅ Use relative paths
✅ Version control everything
✅ Make data acquisition reproducible
✅ Comment your code
setwd() in scriptsDon’t Worry If This Seems Complex!
This is a preview of what we’ll practice in detail on Day 2/3. You’re welcome to try now, but no pressure!
Complete workflow preview:
Create new repository on GitHub called “r-practice”
Clone it and create R Project in RStudio
Create file analysis.R with simple code:
Stage, commit with message “Add first analysis”
Push to GitHub
Edit file, add: print(summary(y))
Commit with message “Add summary statistics”
Push again
View your commit history on GitHub!
Tip
Alternative: Just focus on creating the GitHub account and installing Git today. We’ll practice the workflow together on Day 2/3!
What we’ve covered today:
Coming up next:
Git Learning Path
Today: Understand what Git is and why it matters
Day 2/3: Master Git workflows with guided practice
Beyond: Use Git confidently in your research
Start small, be consistent:
These habits compound over time 🚀
Before Next Session (Day 2/3)
Required:
Optional:
Save for Day 2/3:
Focus Today
Get your tools installed and accounts created. We’ll learn Git by doing on Day 2/3!
Contact:
Course Materials: