Introduction to R and Rstudio

Session - import csv from the web

Zoë Turner

URLs imports

Sometimes it’s easier to directly retrieve the csv files from the source on the internet.

This removes a step in the Reproducible Analytical Pipeline where a person is required to save the file to import.

Importing csvs using {readr}

We will use the “Import Dataset” button which is the same way to get csv files from a computer:

Screenshot of RStudio with Import Dataset drop down button highlighted

File location - using a url

Instead of selecting a file, instead copy the url into the File/URL box next to Browse

https://www.ethnicity-facts-figures.service.gov.uk/culture-and-community/digital/internet-use/latest/downloads/by-ethnicity.csv

Browse changes to Update which will pressed will give a preview and the code is:

library(readr)
by_ethnicity <- read_csv(url("https://www.ethnicity-facts-figures.service.gov.uk/culture-and-community/digital/internet-use/latest/downloads/by-ethnicity.csv"))

End session