Assignment 6: R APIs and Databases

Author

Matthew DeHaven

Published

March 23, 2026

1 Accept Assignment on Github Classroom

  1. Accept Assignment 6 on Github Classroom.

  2. Clone this assignment to your computer.

  3. Intitialize your own renv environment.

2 Set up “secrets.r” file

  • Copy the “secrets-template.r” file to a new “secrets.r” file

This will be where you will store your personal API keys and passwords.

I have already added “secrets.r” to the “.gitignore”, so it should not be tracked or pushed to Github.

3 FRED API

3.1 Pull FRED Series

You will need to use the fredr package for this section.

  • Pull the following data series
    • Real GDP: “GDPC1”
    • Rhode Island Unemployment Rate: “RIUR”
    • US-Euro Spot Exchange Rate: “DEXUSEU”
    • One more series of your choice, look around FRED’s website
  • For each series, calculate the following:
    • Mean
    • Median
    • 25th Percentile
    • 75th Percentile
  • Now report the same summary statistics, but only with data since 2020

3.2 Vintage FRED

  • Pull Real GDP using a vintage date

    • There is a vintage_dates argument in the fredr() function.
  • Calculate the difference between the current and the vintage data series (if there is no difference, try another vintage date)

  • Print out the date with the maximum difference

4 tidycensus API

  • Request a Census API key: https://api.census.gov/data/key_signup.html

    • Save it to your “secrets.r” file
  • Install the sf package

  • Install the tidycensus package

  • Pull median household income: “B19013_001” from the ACS1

    • But choose a different state than Rhode Island
  • Create a map with the data and ggplot2

    • Follow the example in the slides

1 Same as the example in the slides.

(Optional) Mapview

If you want to try making one of those interactive maps, install the package mapview and give it a go.

5 Connect to WRDS Database

Warning

This can take 1-2 days to get access.

  • Once you have an account, make sure you can log into WRDS online: https://wrds-www.wharton.upenn.edu

  • Then add your account username and password to the “secrets.r” file.2

  • Then open up the “get-wrds-data.r” script

    • The connection to the WRDS database should already work
    • Run the example in the code (same as what we saw in class)
    • Find another database to connect to and pull a subset of the data
      • I’d suggest looking around on the WRDS website to see what data is available

2 Sometimes you have to approve the connection through the Duo app on your phone.

6 Submit

  • Take a renv::snapshot() to update your renv.lock file
  • Commit your code and push to Github!