5.1 Reading data directly

In the modern R world, a lot of the work of accessing web resources is baked into common data loading packages. Many packages allow you to read directly from a URL as if it were a file on your local machine.

The Tidy Tuesday project is a great resource for a varied set of real world examples of loading and working with CSV datasets and spatial data.

The code below is taken directly from a Tidy Tuesday Australian Bushfires collection from early 2020. This example reads CSV data directly from web links using readr, and spatial data from JSON using sf.

# Get the Data

rainfall <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-07/rainfall.csv')
temperature <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-07/temperature.csv')

# IF YOU USE THIS DATA PLEASE BE CAUTIOUS WITH INTERPRETATION
nasa_fire <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-07/MODIS_C6_Australia_and_New_Zealand_7d.csv')

# For JSON File of fires
url <- "http://www.rfs.nsw.gov.au/feeds/majorIncidents.json"

aus_fires <- sf::st_read(url)

If you need to load data from a web source, check the help page for your read function and see if it supports reading from URLs as well as local file paths before you dive into anything more complicated.