-
Notifications
You must be signed in to change notification settings - Fork 7
/
README.Rmd
124 lines (93 loc) · 4.32 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE, comment = "#>", out.width = "100%",
fig.path = "man/figures/README-", fig.width = 7, fig.height = 4, dpi = 150,
message = FALSE, warning = FALSE, error = FALSE
)
library(eia)
library(ggplot2)
```
# eia <img src="man/figures/logo.png" style="margin-left:10px;margin-bottom:5px;" width="120" align="right">
<!-- badges: start -->
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/)
[![R-CMD-check](https://github.com/ropensci/eia/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ropensci/eia/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/ropensci/eia/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ropensci/eia?branch=master)
[![](https://badges.ropensci.org/342_status.svg)](https://github.com/ropensci/software-review/issues/342)
[![CRAN status](https://www.r-pkg.org/badges/version/eia)](https://cran.r-project.org/package=eia)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/eia)](https://cran.r-project.org/package=eia)
[![Github Stars](https://img.shields.io/github/stars/ropensci/eia.svg?style=social&label=Github)](https://github.com/ropensci/eia)
<!-- badges: end -->
The `eia` package provides API access to data from the US [Energy Information Administration](https://www.eia.gov/) (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](https://www.eia.gov/opendata/register.php).
A valid email and agreement to the API Terms of Service is required to obtain a key.
`eia` includes functions for searching the EIA API data directory and importing various 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 data metadata. The package also provides control over API key
storage and caching of API request results.
## Installation
Install the CRAN release of `eia` with
```{r instl1, eval=FALSE}
install.packages("eia")
```
or install the development version from GitHub with
```{r instl2, eval=FALSE}
# install.packages("remotes")
remotes::install_github("ropensci/eia")
```
## Example
After obtaining the API key, store it somewhere such as `.Renviron` and never have
to do anything with the key when using the package. Alternatively, set it manually
with `eia_set_key()` in the current R session. Further, it can always be passed
explicitly to the `key` argument of a given `eia` function.
### Load package and set key
```{r xmpl1, eval=FALSE}
library(eia)
# not run
eia_set_key("yourkey") # set API key if not already set globally
```
### Explore the API directory
Get a list of the EIA's data directory (and sub-directories) with `eia_dir()`.
```{r xmpl2}
# Top-level directory
eia_dir()
# Electricity sub-directory
eia_dir("electricity")
```
### Get data
Get annual retail electric sales for the Ohio residential sector since 2010
```{r xmpl3}
(d <- eia_data(
dir = "electricity/retail-sales",
data = "sales",
facets = list(stateid = "OH", sectorid = "RES"),
freq = "annual",
start = "2010",
sort = list(cols = "period", order = "asc"),
))
```
and make a nice plot.
```{r plt}
library(ggplot2)
ggplot(d, aes(x = period, y = sales / 1e3)) +
geom_bar(col = "steelblue", fill = "steelblue", stat = "identity") +
theme_bw() +
labs(
title = "Annual Retail Sales of Electricity (GWh)",
subtitle = "State: Ohio; Sector: Residential",
x = "Year", y = "Sales (GWh)"
)
```
## References
See the collection of vignette tutorials and examples as well as complete package
documentation available at the `eia` package [website](https://docs.ropensci.org/eia/).
---
Please note that the `eia` project is released with
a [Contributor Code of Conduct](https://github.com/ropensci/eia/blob/master/CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.
[![ropensci_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org)