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
.pkg
file 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.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
.Rmd
files 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!
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
├── codebook.Rmd # DON'T EDIT - copy/rename instead
├── (other course files) # DON'T TOUCH - various course materials
├── my_notes/ # CREATE - your folder for notes
│ ├── lesson1_notes.Rmd
│ ├── practice.R
│ └── other_notes.Rmd
└── codebook_lastname.Rmd # CREATE - copy of codebook with your name
For the codebook: Copy codebook.Rmd
and rename it to codebook_lastname.Rmd
(replace “lastname” with your actual last name). This file includes homework questions and space for your notes.
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 Find the Console:
Look for the Console panel in RStudio (bottom left). You’ll see a >
symbol where you can type.
1.9.2 Install Packages:
First, locate the Console in RStudio: Look at the bottom left panel of RStudio. You’ll see a panel labeled “Console” with a >
symbol - this is where you type R commands.
Click in the Console and paste this entire block of code (it will take 10-15 minutes):
# Install basic tools first
install.packages(c("devtools", "BiocManager", "tidyverse", "rmarkdown"))
# Install Bioconductor (for biological data analysis)
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
# Install all required packages for the course
BiocManager::install(c(
"bookdown", "clusterProfiler", "DESeq2", "dplyr", "enrichplot", "fgsea",
"ggplot2", "ggrepel", "gplots", "knitr", "org.Hs.eg.db", "pheatmap",
"purrr", "RColorBrewer", "rmarkdown", "rsconnect", "tidyverse", "tinytex"
))
# Install course-specific package
devtools::install_github("gurinina/GOenrichment", force = TRUE)
# Install document creation tools
if (!tinytex::is_tinytex()) {
tinytex::install_tinytex(force = TRUE)
}
Be patient! This process downloads and installs many packages. You’ll see lots of text scrolling by - this is normal.
1.10 Step 8: Verify Everything Works
Let’s test that all packages installed correctly:
1.10.1 In the Console, paste and run:
Remember: The Console is the bottom left panel in RStudio with the >
symbol.
1.10.2 Test Creating a Document:
- In RStudio, go to File → New File → R Markdown
- Leave the default settings and click OK
- Click the “Knit” button at the top
- If a webpage opens with a document, everything is working perfectly!
1.10.3 Creating PDF Documents:
If you want to create PDF files (instead of HTML), you need to modify the document header:
- For documents with special characters or emojis: Change the top of your document to:
- For simple documents: You can use:
Note: If you get errors about Unicode characters when making PDFs, always use latex_engine: xelatex
in your document header.
1.11 What Success Looks Like
✅ RStudio opens without errors
✅ You can type 2 + 2
in the Console and get [1] 4
✅ You can create a new R Markdown document and “Knit” it
✅ You have a folder with course materials from the main repository
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
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 journey.