Author: Matthew Leonawicz
License: MIT

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Travis build status AppVeyor Build Status Codecov test coverage

CRAN status CRAN RStudio mirror downloads Github Stars

The eia package provides API access to data from the US Energy Information Administration (EIA).

Pulling data from the US Energy Information Administration (EIA) API requires a registered API key. A key can be obtained at no cost here. A valid email and agreement to the API Terms of Service is required to obtain a key.

eia includes functions for searching EIA API data categories and importing time series and geoset time series datasets. Datasets returned by these functions are provided in a tidy format or alternatively in more raw form. It also offers helper functions for working with EIA API date strings and time formats and for inspecting different summaries of series metadata. The package also provides control over API key storage and caching of API request results.


Install the CRAN release of eia with


To install the development version from GitHub use

# install.packages("remotes")


To begin, store your API key. You can place it somewhere like your .Renviron file and never have to do anything with the key when you use the package. You can set it with eia_set_key in your R session. You can always pass it explicitly to the key argument of a function.


# not run
eia_set_key("yourkey") # set API key if not already set globally

Load a time series of net electricity generation.

id <- "ELEC.GEN.ALL-AK-99.A"
(d <- eia_series(id, n = 10))
#> # A tibble: 1 x 13
#>   series_id name  units f     description copyright source iso3166
#>   <chr>     <chr> <chr> <chr> <chr>       <chr>     <chr>  <chr>  
#> 1 ELEC.GEN~ Net ~ thou~ A     "Summation~ None      EIA, ~ USA-AK 
#> # ... with 5 more variables: geography <chr>, start <chr>, end <chr>,
#> #   updated <chr>, data <list>

#> # A tibble: 10 x 3
#>    value date        year
#>    <dbl> <date>     <int>
#>  1 6247. 2018-01-01  2018
#>  2 6497. 2017-01-01  2017
#>  3 6335. 2016-01-01  2016
#>  4 6285. 2015-01-01  2015
#>  5 6043. 2014-01-01  2014
#>  6 6497. 2013-01-01  2013
#>  7 6946. 2012-01-01  2012
#>  8 6871. 2011-01-01  2011
#>  9 6760. 2010-01-01  2010
#> 10 6702. 2009-01-01  2009

unnest(d, cols = data) %>% ggplot(aes(year, value)) +
  geom_line() + labs(y = d$units, title = d$name)


See the collection of vignette tutorials and examples as well as complete package documentation available at the eia package website.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.