install.packages(c("rmarkdown", "quarto"))ECON 465 Week 1 Lab Handout: Setting Up R, RStudio, and Quarto
Reproducible Economic Research Setup + First Exercises
1 Before You Start
1.1 Lab Goal
This lab is designed for self-installation.
Please complete all steps before class and come prepared to run the exercises.
This is your first step toward becoming a data-driven economist.
1.2 Lab Objectives
By the end of this lab, you will be able to:
- Install and configure R, RStudio, and Quarto
- Create a structured RStudio Project
- Write and execute basic R commands
- Use essential keyboard shortcuts
- Install and load R packages
- Create, edit, and render a Quarto document
1.3 Pre-Lab Checklist
You will need:
- A laptop with internet access
- 30–45 minutes of uninterrupted time
2 Install the Software (30 minutes)
We will use the standard toolkit of modern economic research:
- R → statistical programming language
- RStudio → integrated development environment
- Quarto → reproducible publishing system
2.1 Install R
Go to: https://cran.r-project.org
Select your operating system:
- Windows → Download R for Windows → base
- macOS → Download R for macOS (choose correct chip version)
- Linux → Follow distribution-specific instructions
- Windows → Download R for Windows → base
Install using default settings.
2.1.1 Verification
Open R once.
If you see a console window with > prompt, installation is successful.
2.2 Install RStudio Desktop
- Go to: https://posit.co/download/rstudio-desktop/
- Download RStudio Desktop (Free)
- Install using default settings.
2.2.1 Verification
Open RStudio.
You should see:
- Console (bottom-left)
- Environment/History (top-right)
- Files/Plots/Packages/Help (bottom-right)
2.3 Install Quarto
Quarto is the publishing engine that allows us to combine:
- Text
- Code
- Output
into a single reproducible document.
You do not need to manually download anything from quarto.org during this lab.
2.3.1 Step 1 — Install Required R Packages
Open RStudio and run the following in the Console:
These packages enable document rendering inside R.
2.3.2 Step 2 — Verify Quarto Installation
After installation, restart RStudio.
Then in the Console, run:
quarto::quarto_version()[1] '1.8.25'
If Quarto is properly available, you should see a version number printed.
2.3.3 Step 3 — Confirm Rendering Works
In RStudio:
File → New File → Quarto Document
If this option appears in the menu, your installation is complete.
2.3.4 Why This Matters
Quarto ensures:
- Reproducibility
- Transparent research workflow
- Professional-quality reports
In this course, all assignments will be submitted as Quarto documents.
3 Create Your First Reproducible Project
A reproducible workflow means:
Your future self (and your instructor) can run your project and obtain the same results.
In this course, every analysis must live inside a structured project folder.
3.1 Create an RStudio Project
In RStudio:
File → New Project → New Directory → New Project
- Directory name:
econ_465_week2 - Choose a location
- Leave Create a git repository unchecked (we will learn Git later)
- Click Create Project
3.1.1 Verification
You should see the project name displayed in the top-right corner of RStudio.
You are now “inside” your project.
3.2 Create a Clean Folder Structure
In the Files pane (bottom-right), click New Folder and create:
data/scripts/reports/figures/
3.2.1 Why this matters
Professional data scientists separate:
- raw data
- analysis scripts
- reports
- outputs
Clean structure prevents confusion and ensures reproducibility.
4 R Basics
Before we analyze economic data, we must understand how R works.
4.1 Console vs Script
- The Console runs commands immediately (temporary use).
- A Script saves your code permanently (reproducible research).
4.1.1 Step 1 — Create Your First Script
In RStudio:
File → New File → R Script
Save it as:
scripts/week1_basics.R
4.1.2 Step 2 — Copy and Run the Following Code
# Basic arithmetic
2 + 2[1] 4
10 / 4[1] 2.5
# Creating objects (variables)
x <- 10
y <- 3
x + y[1] 13
x / y[1] 3.333333
# A numeric vector (example: GDP growth rates)
gdp_growth <- c(4.7, 5.6, -1.8, 3.2)
# Calculate the mean growth rate
mean(gdp_growth)[1] 2.925
4.1.3 Verification
You should see numeric outputs appear in the Console.
If nothing happens, check that you pressed:
- Ctrl + Enter (Windows)
- Cmd + Enter (Mac)
4.2 Essential Key Bindings
Using shortcuts will save you hours this semester.
4.2.1 Run current line or selection
- Windows:
Ctrl + Enter - macOS:
Cmd + Enter
4.2.2 Insert pipe operator (|> or %>%)
- Windows:
Ctrl + Shift + M - macOS:
Cmd + Shift + M
4.2.4 Small Practice Exercise
Add the following to your script and run it:
inflation <- c(8.2, 10.5, 6.1, 12.3)
mean(inflation)[1] 9.275
sd(inflation)[1] 2.70108
Ask yourself:
- What does
mean()compute? - What does
sd()represent economically?
You are now ready to move from simple calculations to real economic datasets.
5 Packages: Install Once, Load Often
R is powerful because of its packages — collections of functions written by other researchers and developers.
In this course, we will use packages for:
- Data wrangling
- Visualization
- Modeling
- Reproducible reporting
5.1 Install Required Packages
You only need to install a package once.
Run the following in the Console:
install.packages(c(
"tidyverse",
"tidymodels",
"janitor",
"skimr",
"palmerpenguins"
))5.1.1 What these packages do
- tidyverse → data manipulation & visualization
- tidymodels → machine learning framework
- janitor → clean variable names
- skimr → quick data summaries
- palmerpenguins → example dataset for practice
If installation fails, check your internet connection and try again.
5.2 Task 4.2 — Load the Packages
After installation, load them in your script:
library(tidyverse)
library(tidymodels)
library(janitor)
library(skimr)
library(palmerpenguins)5.2.1 Verification
If no red error messages appear, the packages loaded successfully.
If you see: > “there is no package called …”
Re-run the installation step.
5.3 Quick Practice
Test whether everything works:
penguins |>
glimpse()Rows: 344
Columns: 8
$ species <fct> Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…
$ island <fct> Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…
$ bill_length_mm <dbl> 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …
$ bill_depth_mm <dbl> 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …
$ flipper_length_mm <int> 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…
$ body_mass_g <int> 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …
$ sex <fct> male, female, female, NA, female, male, female, male…
$ year <int> 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…
You should see a structured summary of the dataset.
This confirms that:
- R is working
- Packages are installed
- You are ready for analysis
6 What Is a Quarto Document?
A Quarto document (.qmd) combines:
- Written explanation (Markdown text)
- R code chunks
- Output (tables, figures, results)
When you click Render, Quarto:
- Runs all R code
- Captures the output
- Produces a clean HTML (or PDF) document
This ensures:
- Transparency
- Reproducibility
- Professional presentation
6.1 Anatomy of a Quarto File
A Quarto file has three main parts:
6.1.1 1. YAML Header (at the top)
Contains metadata like:
- Title
- Author
- Output format
Example:
---
title: "My Analysis"
author: "Your Name"
format: html
---6.1.2 2. Text (Markdown)
Normal writing like this:
- You can create headings using
# - Bold with
**text** - Lists with
-
6.1.3 3. Code Chunks
R code must be placed inside code chunks:
2 + 2[1] 4
When rendered, the code runs and prints the result.
6.2 Why Quarto Matters in Economics
In modern economic research:
- Analysis must be reproducible
- Code and results must be transparent
- Reports must be clear and professional
Quarto allows you to:
- Combine narrative and evidence
- Avoid copy–paste errors
- Share work publicly (e.g., RPubs)
6.3 Reflection Question
Why is reproducibility especially important in economics?
Write 2–3 sentences answering this question in your Quarto document.
7 Create and Render Your First Quarto Document
7.1 Create the File
In RStudio:
File → New File → Quarto Document…
- Title: Week 1: First Quarto Report
- Author: Your Name
- Format: HTML
Save the file inside the reports/ folder as:
week2_report.qmd
7.2 Add Setup Chunk
Paste the following directly below your YAML header:
7.2.1 What this does
label: setupnames the chunk.include: falseruns the code but hides it in the final report.- We load required packages once at the beginning.
7.3 Add Your First Output
Below the setup chunk, add:
penguins |>
count(species)# A tibble: 3 × 2
species n
<fct> <int>
1 Adelie 152
2 Chinstrap 68
3 Gentoo 124
7.3.1 What this does
- Counts observations by species.
- Produces a clean summary table.
7.4 Add a Plot
Now add:
penguins |>
ggplot(aes(x = bill_length_mm)) +
geom_histogram(binwidth = 2) +
labs(
title = "Distribution of Bill Length",
x = "Bill length (mm)",
y = "Count"
)7.4.1 What this does
- Creates a histogram of bill length.
- Adds clear axis labels and a title.
7.5 Render Your Document
Click the Render button at the top of the editor.
Quarto will:
- Run all code
- Generate an HTML file
- Open it in the Viewer pane
7.5.1 Verification
You should see:
- A table with species counts
- A histogram
- Your title and name at the top
If you see errors:
- Check that packages were installed
- Confirm the setup chunk appears below YAML
- Re-run
library()commands
8 Publish to RPubs
Once your document renders successfully:
- Click Publish (top-right of the Viewer pane)
- Choose RPubs
- Log in (create account if necessary)
- Confirm publish
After publishing:
- Copy the RPubs link
- Save the link for submission
8.1 Final Check Before Submission
Make sure:
- The document renders without errors
- Your name appears at the top
- The table and histogram are visible
- You can open your RPubs link in a browser
You have now created and published your first reproducible economic analysis.
This week, we begin working with real macroeconomic data.
4.2.3 Comment or uncomment lines
Ctrl + Shift + CCmd + Shift + C