R Tutorial: Introduction: Working With Web Data in R

Oliver Keyes and Charlotte Wickham teach how to pull data from the web into R. You'll learn to download CSVs from URLs, make API requests with httr, parse JSON and XML, and scrape HTML with CSS selectors.
Chapters
Hi, I'm Oliver Keyes.
And I'm Charlotte Wickham.
Welcome to Working with Web Data in R. It turns out that the Internet is a great place to find datasets, and this course teaches you how to get those data sets into R in order to analyze them. You'll start with the simplest cases, simply downloading files to your machine and using existing packages specifically designed for pulling in web data. Next, you'll use the tidyverse package HTTR to query web application programming interfaces using the get and Post commands.
After that, you'll learn how to work with JSON and xml, the two most common data formats used by websites. Typically, datasets in R are rectangular so they can be stored in a data frame or matrix. JSON and XML are both nested data structures, so you'll learn new techniques to to Explore them, including XPath, the XML query language.
Finally, you'll learn to use cascading style sheets or CSS to navigate HTML pages and extract their data.
First, let's begin with the easy case. Many functions in base are that are used for importing data except a URL, so you can directly import the data from its location on the Internet. For example, to retrieve a CSV file that you found on the Internet, you can still use read CSV. The only change to your code is that rather than passing in a path to a local file is that you pass in a URL.
Since downloading data from the Internet every time that you want to use it can be very slow and tedious, especially for large data sets. R provides the function Download file to copy Internet based files to your machine. This takes two arguments, the URL where the file lives and a path to somewhere on your local file system that you want to download the data to. Now let's try some examples.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







