Lab 5. Recreate Visualization from Public Source

(No Class)

Xindi (Cindy) Hu, ScD

2025-06-19

No Class Today

Reading assignment:

Lab:

Please accept the Lab 5 assignment on GitHub Classroom and follow the tutorial on your own time. See the #announcement channel in Slack for the link. As always, labs are due next Monday June 23, 2025, at 11:59 PM.

How to store API key without committing it to GitHub

To use the {tidycensus} package, you need to set up a Census API key. You can obtain one from the Census Bureau’s website.

You can store your API key in a .Renviron file in your repository’s root directory (same directory as your .Rproj). Add .Renviron to .gitignore so that this file is not committed to GitHub.

How to store API key without committing it to GitHub

Then in your R scripts, you can access the API key using Sys.getenv("CENSUS_API_KEY"). This way, you can use the API key without hardcoding it into your scripts.

library(tidycensus)
invisible(
  census_api_key(Sys.getenv("CENSUS_API_KEY"), install = TRUE, overwrite = TRUE)
)
options(tigris_use_cache = TRUE)

Protect yourself against this!

Source: Reddit