Chapter 1 Getting Started with R and RStudio
1.2 What You’re Installing and Why
Before we start, here’s what each tool does:
- R: The programming language that does the actual data analysis
- RStudio: A user-friendly interface that makes R easier to use (like Microsoft Word for documents)
- Git: Software that helps you download and sync course materials
- Additional tools: Help R work with different types of data and create documents
Important: Install everything in the order listed below. Each step builds on the previous one.
1.3 Step 1: Install R
R is the programming language. Install this first!
1.3.1 For Windows:
- Go to R Project website
- Click “base” then “Download R for Windows”
- Run the downloaded file and follow the installation prompts
1.3.2 For macOS:
These instructions work for ALL Macs (Intel and Apple Silicon):
- Go to R Project website
- Download the Intel (x86_64) version (yes, even for newer Macs with M1/M2/M3 chips)
- Run the downloaded
.pkgfile and follow the installation prompts
1.4 Step 2: Install Additional Tools (macOS Only)
Windows users can skip to Step 3. Mac users need these tools for R to work properly:
1.4.1 Install Required System Tools:
Open Terminal (found in Applications → Utilities) and paste each command one at a time:
Click “Install” when prompted and wait for it to finish (this may take 10-15 minutes).
1.4.2 Install Graphics Support:
- Go to XQuartz.org
- Download and install XQuartz
- Log out and log back in to your Mac after installation
1.4.3 Install Fortran Compiler:
- Go to R Tools for macOS
- Download gfortran-12.2-universal.pkg
- Install it by double-clicking the downloaded file
1.4.4 Add Fortran to Your System Path:
In Terminal, paste these commands:
echo 'export PATH="/opt/gfortran/bin:/usr/local/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/gfortran/bin:/usr/local/bin:$PATH"' >> ~/.bash_profileQuit terminal and restart. In terminal, type:
It should say GNU Fortran (GCC) 12.2.0. You’re all set.
1.5 Step 3: Install Git
Git helps you download and sync course materials.
1.5.1 For Windows:
- Go to git-scm.com
- Download Git for Windows
- Run the installer using all default settings (just keep clicking “Next”)
1.6 Step 4: Install RStudio
RStudio is the user-friendly interface for R.
- Go to RStudio.com
- Download RStudio Desktop (the free version)
- Install it like any other program
1.7 Step 5: Test Your Installation
Let’s make sure everything works:
1.7.1 Test RStudio and R:
- Open RStudio (not R - always use RStudio)
- You should see 4 panels:
- Console (bottom left) - this is where you type R commands
- Environment (top right) - shows your data
- Files/Plots (bottom right) - shows files and graphs
- Script (top left) - for writing longer code
- Click in the Console (the bottom left panel where you see
>) - Type this and press Enter:
You should see [1] 4
1.8 Step 6: Download Course Materials
Now let’s get the main course files:
- In RStudio, go to File → New Project → Version Control → Git
- In the “Repository URL” field, paste:
https://github.com/gurinina/2025_IntroR_and_RStudio
- Choose where to save the project on your computer
- Click “Create Project”
RStudio will download all course materials. This may take a few minutes.
1.8.1 Additional Repositories:
As the course progresses, you may need to clone additional repositories for specific modules. Your instructor will provide those URLs when needed.
Tips:
- To update materials later in the term, open the project and click the Pull button in the Git tab
- To switch between projects later: RStudio → File → Open Project… and select the corresponding .Rproj file
1.8.2 Understanding the Git Pane:
When you open your course project in RStudio, you should see a tab labeled Git in the upper-right panel (next to Environment and History). This is where you can:
- See changes you’ve made to files (they’ll appear in the list)
- Revert changes if you made an edit you don’t want to keep
- Pull to update your local copy with the newest course materials from GitHub
- Push to send your own changes to GitHub (not applicable in this course — you won’t be pushing)
For this course, you will mainly use the Pull button (blue down-arrow icon) to update your files when the instructor posts new material.
1.8.3 IMPORTANT: Git Best Practices for Students
To avoid problems when updating course materials, follow these rules:
1.8.3.1 ✅ Safe Things to Do:
- Create new files for your notes and practice work
- Rename template files before editing them (like
codebook_yourname.Rmd) - Make new folders like
my_notes/orhomework/for your work - Copy lesson files to a new name before modifying them
1.8.3.2 ⛔ Things That Cause Git Conflicts:
- Don’t edit the original lesson
.Rmdfiles directly - Don’t modify existing file names in the lessons folder
- Don’t save your work in the main lesson directories
1.8.3.3 Golden Rule:
Never edit the original lesson files directly. Always create new files for your notes and practice. This way you can always Pull the latest updates without problems!
For the codebook: Copy 17-introR_codebook_template.Rmd and rename it to <lastname>_17-introR_codebook.Rmd (replace “lastname” with your actual last name). This file includes homework questions and space for your notes.
1.8.3.4 Suggested Workflow:
2025_IntroR_and_RStudio/
├── lessons/ # DON'T TOUCH - instructor files
├── img/ # DON'T TOUCH - course images
├── _book/ # DON'T TOUCH - bookdown output
├── 17-introR_codebook_template.Rmd # DON'T EDIT - copy/rename instead
├── (other course files) # DON'T TOUCH - various course materials
├── student_notes/ # YOUR FOLDER for notes
│ ├── <lastname>_17-introR_codebook.Rmd
│ ├── practice.R
│ └── other_notes.Rmd
1.9 Step 7: Install Required R Packages
R packages are like apps that add extra features. We need several for this course.
1.9.1 Important: Locate the Console First
Before running any code, you need to find the Console in RStudio:
- Open RStudio
- Look at the bottom left panel - this is the Console
- You’ll see a
>symbol - this is where you type R commands - Click in this area to make sure your cursor is active in the Console
1.9.2 COPY AND PASTE THIS CODE INTO THE CONSOLE:
Click in the Console (bottom left panel with the > symbol) and paste this entire block of code:
# Set CRAN mirror first (this tells R where to download packages)
options(repos = c(CRAN = "https://cloud.r-project.org/"))
# Install basic tools first
install.packages(c("BiocManager", "devtools", "ggraph", "tidyverse"))
# Install Bioconductor (for biological data analysis)
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
# Install all required packages for the course
BiocManager::install(c(
"apeglm", "bookdown", "clusterProfiler", "colorspace", "DESeq2", "details", "dplyr", "enrichplot", "fansi", "fgsea", "ggplot2", "ggrepel", "ggridges", "ggthemes", "gplots","GO.db", "GOSemSim", "igraph", "knitr", "org.Hs.eg.db", "patchwork", "pheatmap", "purrr", "RColorBrewer", "rmarkdown", "rsconnect", "scales", "tidydr", "tidyr" ,"tidyverse", "tinytex", "visNetwork"
))
# Install course-specific package
devtools::install_github("gurinina/GOenrichment", force = TRUE)
# Install document creation tools
if (!tinytex::is_tinytex()) {
tinytex::install_tinytex(force = TRUE)
}1.10 Step 8: Verify Everything Works
Let’s test that all packages installed correctly.
1.10.1 COPY AND PASTE THIS TEST CODE INTO THE CONSOLE:
Again, click in the Console (bottom left panel) and paste this code:
# Check if key packages work
library(ggplot2)
library(dplyr)
library(DESeq2)
# If no error messages appear, you're ready!
cat("Success! All packages are working.\n")If you see “Success! All packages are working.” then everything is installed correctly!
1.11 What Success Looks Like
✅ RStudio opens without errors
✅ You can type 2 + 2 in the Console and get [1] 4
✅ You have a folder with course materials from the main repository
✅ The test code runs without errors and shows “Success!”
1.12 Common Problems and Solutions
1.12.1 “Package not found” errors:
- Make sure you’re typing in the Console (bottom left panel)
- Try restarting RStudio and running the code again
- Make sure you pasted the CRAN mirror line:
options(repos = c(CRAN = "https://cloud.r-project.org/"))
1.12.3 RStudio can’t find Git:
- Make sure you installed Git before RStudio
- Restart RStudio completely (quit and reopen)
1.13 Getting Help
If something doesn’t work:
- Try restarting RStudio
- Try restarting your computer
- Ask a classmate or instructor
- Email the instructor with:
- What step you’re on
- What error message you see (copy and paste it)
- A screenshot if helpful
Remember: Software installation can be tricky, even for experienced users. Don’t worry if you need help - this is completely normal!
1.14 Next Steps
Once everything is installed:
- Explore RStudio - click around and see what’s in each panel
- Try the built-in R tutorial: In the Console, type:
- Read the course materials you downloaded
- Don’t panic! Learning R takes time, and everyone starts as a beginner
Welcome to R! You’re ready to start your data analysis