RStudio Projects and GitHub
1 Purpose
This SOP provides instructions for setting up RStudio, connecting it to GitHub, and managing collaborative research projects using version control. R (R Core Team, 2024), RStudio (Posit PBC, 2024), and GitHub (GitHub Inc., 2024) together enable collaborative, transparent, reproducible, and accessible data analysis. For a comprehensive practical guide, see (Bryan, 2023).
2 Scope
- Applies to: All EA Program researchers using R for data analysis and collaborative projects
- Does not apply to: Local-only R scripts with no version control; Python or other language workflows
- Location: RStudio Server at Pomona College; local installations
3 Acknowledgements
Substantial contributions: Aparna Chintapalli and Isaac Medina. We acknowledge all students who have followed these instructions and suggested improvements.
4 Definitions
- R: A free, open-source programming environment for statistical computing, maintained by a global community of statisticians and programmers (R Core Team, 2024).
- RStudio: A user interface for R that provides tools to write code, view results, manage files, and integrate with version control. Available as a desktop application or via the Pomona College server (Posit PBC, 2024).
- GitHub: A web-based hosting service for Git repositories that enables collaborative code and document management (GitHub Inc., 2024).
- Repository (repo): A GitHub project folder that contains all files, history, and collaboration settings.
- Version control: A system that tracks changes to files over time, allowing multiple people to collaborate while maintaining a complete history of who changed what and when.
- SSH key: A cryptographic key pair used to establish a secure connection between RStudio and GitHub without entering a password each time.
- Clone: Creating a local copy of a GitHub repository on your computer or server.
- Branch: A parallel line of development that lets you work on a feature or fix without affecting the main codebase until you are ready to merge.
- Pull: Downloading the latest changes from GitHub to your local copy.
- Commit: Saving a snapshot of your changes with a descriptive message.
- Push: Uploading committed changes from your local copy to GitHub.
- Pull request (PR): A request to merge changes from one branch into another; the standard review mechanism for collaborative repositories.
5 Safety and Hazards
This is a computational procedure with no physical hazards.
6 Accessing RStudio
6.1 Pomona College RStudio Server
The recommended method for EA Program work:
- Open a browser and go to
rstudio.pomona.edu - Log in with your Pomona College credentials
- Your files are stored on the server (no local installation needed)
6.2 Local Installation
Install in this order if working offline:
- R: cran.r-project.org
- RStudio Desktop: posit.co/download/rstudio-desktop
- Git: git-scm.com
7 Setting Up GitHub
7.1 Create a GitHub Account
- Go to github.com and create a free account
- Use your Pomona email address
- Choose a professional username (e.g.,
firstlastorflastname)
7.2 Configure SSH Keys
SSH keys let RStudio communicate with GitHub securely. Set them up once per machine (or server account).
In RStudio, open the Terminal tab
Generate a key pair:
ssh-keygen -t ed25519 -C "your_pomona_email@pomona.edu"Accept the default file location; leave the passphrase blank for server use
Print the public key:
cat ~/.ssh/id_ed25519.pubCopy the output
On GitHub: Settings > SSH and GPG keys > New SSH key > paste and save
Test the connection:
ssh -T git@github.comA message beginning “Hi username!” confirms success.
8 Working with Repositories
8.1 Clone an Existing Repository
- On GitHub, navigate to the repository and click Code > SSH
- Copy the SSH URL (
git@github.com:org/repo.git) - In RStudio: File > New Project > Version Control > Git
- Paste the URL; choose a local directory; click Create Project
8.2 The Pull-Edit-Commit-Push Workflow
Always pull before editing to avoid merge conflicts:
- Pull: Click the blue down-arrow in the Git pane (or
git pull) - Edit: Make your changes in R scripts or
.qmdfiles - Stage: Check boxes next to changed files in the Git pane
- Commit: Click Commit; write a clear message (e.g.,
"Add soil texture analysis for sites 4-6") - Pull again: Pull once more before pushing to catch any concurrent changes
- Push: Click the green up-arrow to push to GitHub
8.3 Branching Workflow
For experimental analyses or features that are not yet ready for the main branch:
git checkout -b feature/my-analysis # create and switch to new branch
# ... make changes and commits ...
git push -u origin feature/my-analysis
# Open a Pull Request on GitHub when ready to merge9 Writing Quarto Documents
9.1 Rmd vs. Qmd
| Feature | Rmd | Qmd |
|---|---|---|
| Maintained by | RStudio/Posit | Quarto project (open source) |
| Requires R | Yes | No (also supports Python, Julia) |
| Chunk options | In header: {r, echo=TRUE} |
On lines: #| echo: true |
| SOP system uses | Legacy | Preferred for new documents |
For new EA Program documents, use .qmd. Existing .Rmd files will continue to work.
#| echo: trueshows the code in the output (use for teaching)#| echo: falsehides the code (use for reports)#| eval: falseshows the code but does not run it#| fig-cap: "Caption text"adds a figure caption#| warning: falsesuppresses warning messages
10 Recommended Resources
- RStudio YouTube Introduction
- GitHub YouTube Introduction
- Understanding the GitHub Flow
- Happy Git and GitHub for the useR: (Bryan, 2023) – the most comprehensive practical guide
- Quarto Documentation
11 Advanced Topics
11.1 Protecting the Main Branch
For repositories with multiple active contributors, enable branch protection rules on GitHub:
- Go to Settings > Branches > Add rule
- Enter
mainas the branch name pattern - Check Require a pull request before merging
- Optionally check Require approvals (set to 1)
11.2 GitHub Issues for Task Tracking
Create an issue for each task, assign it to a team member, and close it when the work is merged. This creates a record of who did what and when.
11.3 .gitignore
Add file patterns that should never be committed:
.Rhistory
.RData
.Rproj.user/
docs/
_freeze/
*.pdf
12 References
13 Training Record
Before using R/RStudio/GitHub independently for EA Program research, personnel must:
- Read this SOP in full
- Create a GitHub account and configure SSH keys (Sections 11.1–11.3)
- Successfully clone, pull, edit, commit, and push to the
beginnersluckpractice repository (Sections 12–13) - Create and render at least one
.qmdfile (Section 17) - Demonstrate the Pull-Edit-Commit-Push workflow under supervision
- Be signed off by the PI or project lead