Skip to content
R for the Rest of Us Logo

R in 3 Months (Spring 2026)

Downloading and Importing Data

Transcript

Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

View code shown in video
# Load Packages -----------------------------------------------------------

library(tidyverse)
library(fs)
library(readxl)
library(janitor)

# Create Directories ------------------------------------------------------

dir_create("data-raw")

# Download Data -----------------------------------------------------------

# https://www.oregon.gov/ode/educator-resources/assessment/Pages/Assessment-Group-Reports.aspx

download.file(
  "https://www.oregon.gov/ode/educator-resources/assessment/Documents/TestResults2122/pagr_schools_math_tot_raceethnicity_2122.xlsx",
  mode = "wb",
  destfile = "data-raw/pagr_schools_math_tot_raceethnicity_2122.xlsx"
)

download.file(
  "https://www.oregon.gov/ode/educator-resources/assessment/Documents/TestResults2122/TestResults2019/pagr_schools_math_tot_raceethnicity_1819.xlsx",
  mode = "wb",
  destfile = "data-raw/pagr_schools_math_tot_raceethnicity_1819.xlsx"
)

download.file(
  "https://www.oregon.gov/ode/educator-resources/assessment/TestResults2018/pagr_schools_math_raceethnicity_1718.xlsx",
  mode = "wb",
  destfile = "data-raw/pagr_schools_math_raceethnicity_1718.xlsx"
)

download.file(
  "https://www.oregon.gov/ode/educator-resources/assessment/TestResults2017/pagr_schools_math_raceethnicity_1617.xlsx",
  mode = "wb",
  destfile = "data-raw/pagr_schools_math_raceethnicity_1617.xlsx"
)

download.file(
  "https://www.oregon.gov/ode/educator-resources/assessment/TestResults2016/pagr_schools_math_raceethnicity_1516.xlsx",
  mode = "wb",
  destfile = "data-raw/pagr_schools_math_raceethnicity_1516.xlsx"
)

# Import Data ------------------------------------------------------------

math_scores_2021_2022 <-
  read_excel(path = "data-raw/pagr_schools_math_tot_raceethnicity_2122.xlsx") |>
  clean_names()

Your Turn

You’ll be working with data on Oregon school enrollment by race/ethnicity.

  1. Create a new project. Make sure you put it somewhere you’ll be able to find it again later!

  2. Create a new R script file where you’ll do all of your data downloading, cleaning, and importing work.

  3. Download the 2018-2019 through 2022-2023 Fall Membership Report files using the download.file() function into a data-raw folder (which you’ll need to create).

  4. Import the 2022-2023 spreadsheet into a data frame called enrollment_2022_2023, using the clean_names() function from the {janitor} package to make our variable names easy to work with.

Learn More

You can read about all of the arguments for the download.file() function here. If you're very interested in reading in data from the internet, June Choe has put together a very comprehensive article called Read files on the web into R.

To learn about the fs package, check out its documentation.

To learn more about importing Excel files, check out the readxl package documentation. You’ll see, for example, ways to download only certain ranges of cells, which can be helpful when you have messy Excel data!

Other packages I mention in the video are:

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Course Content

144 Lessons