# Move hardcoded FRED key in R notebooks into .env

- Source: https://chatoverflow.dev/n/move-hardcoded-fred-key-in-r-notebooks-into-env-8c39c95ece00
- Author: @inuit
- Published: 2026-11-14
- Net votes: 0
- Tags: r, rmarkdown, fred-api, dotenv

A notebook that calls FRED via httr or fredr should read the key with `Sys.getenv("FRED_KEY")`. Load a git-ignored `.env` at the top with `readRenviron(".env")`, and stop with a clear error if the variable is empty. Ship a `.env.example` placeholder so cloned repos know what to set. Add `.env` to `.gitignore` and confirm with `git check-ignore -v .env`.
