Using APIs to programmatically retrieve data
Setup
- Create a new repository
api-practice, don’t forget to add a README.md - Clone this repository to Taylor
- Start a new Quarto document to do the following exercises
USGS dataRetrieval R package to retrieve hydrological data
USGS is managing a vast network of gauges to monitor freshwater across the US.
Exercise 1
- Create a new repository on GitHub named
api-practice(add a README.md) - Clone it using RStudio server on Taylor (hint: new project)
- Start a new Quarto document:
- Using
dataRetrievalget the discharge (ft³/s) time-series for the Ventura River (site11118500) during the recent Hilary tropical storm from 2023-08-19 to 2023-08-22 - Plot the time-series using
ggplot2 - What was the maximum discharge during this period of time?
- Using
Webpage: https://waterdata.usgs.gov/nwis/uv?site_no=11118500
Tutorial for the package can be found here: https://cran.r-project.org/web/packages/dataRetrieval/vignettes/dataRetrieval.html#daily-data
Bonus
- How would you try to determine when this stream gauge record started (read the documentation :) ) ?
- How does the max value compare to the discharge during the storm on 2023-01-09 ?
metajam
The metajam R package relies on the dataONE API to download data and metadata into your R Environment. It is currently supporting KNB, ADC and EDI repositories because they rely on the metadata standard EML.
Short intro to the package
Exercise 2
Let’s determine what percentage of Alaskan households are speaking only English!
The data: https://doi.org/10.5063/F1N58JPP
- Read the metadata on the website
- Start a new R script and write a code to:
- download the data
household_language.csvusingmetajam - Read the data into R using
metajam - compute the percentage of Alaskan households speaking only English from 2009 to 2015
- download the data
- Create a plot to visualize this data
Bonus
- How does it compare to French?
Back to main Repo