Downloading and Importing Data
This lesson is called Downloading and Importing Data, part of the R in 3 Months (Fall 2025) course. This lesson is called Downloading and Importing Data, part of the R in 3 Months (Fall 2025) course.
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.
Loading transcript...
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.
Create a new project. Make sure you put it somewhere you’ll be able to find it again later!
Create a new R script file where you’ll do all of your data downloading, cleaning, and importing work.
Download the five most recent Fall Membership Report files using the
download.file()function into adata-rawfolder (which you’ll need to create).Import the 2022-2023 spreadsheet into a data frame called
enrollment_2022_2023, using theclean_names()function from thejanitorpackage 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:
I’ve also written an article about cleaning messy data in R. There are many packages to deal with messy data (which often comes in the form of Excel spreadsheets), and I go through several in the post.
And, finally, if you want a really deep dive on data cleaning, check out the course Data Cleaning with R.
Have any questions? Put them below and we will help you out!
Course Content
128 Lessons
You need to be signed-in to comment on this post. Login.