-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
90 lines (54 loc) · 1.86 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
---
title: "EIA API wrapper for R"
output:
md_document:
variant: markdown_github
---
# Introduction
An R client for the EIA API. The API is currently in beta and can be subject to
change.
Before you do anything head over to the [EIA registration page](http://www.eia.gov/beta/api/register.cfm)
and get an API key.
# Installation
```
devtools::install_github("krose/eia")
```
# Examples
```{r, echo=FALSE}
source("api_key.R")
```
Let's first load the library:
```{r loadeia, echo=TRUE}
library(eia)
```
## Category
The first function is the category function. If you don't supply any category_id you will simply get
data on the top level category returned as a list:
```{r cat1, echo=TRUE}
eia_cat(api_key = api_key)
```
These categories are deep, so you might find yourself searching through these until you get
to the data series that you are interested.
Here's the first level of the natural gas category:
```{r cat2, echo=TRUE}
eia_cat(api_key = api_key, category_id = "714804")
```
When you get to the final level the result is often a long list of "childseries" which ids the data
series you can request.
```{r cat3, echo=TRUE}
eia_cat(api_key = api_key, category_id = 475136)
```
## Series
Let's take a look at the annual series from North Dakota and Montana where a part of the Bakken formation is.
```{r series1, echo=TRUE}
eia_series(api_key = api_key,
series_id = c("NG.RES_EPG0_R5302_SND_BCF.A", "NG.RES_EPG0_R5302_SMT_BCF.A"))
```
That's a lot of information and I would rather have it in a more tidy format. When you select "tidy_long"
two additional columns are added, describing the series time frame and the series_id.
```{r series2, echo=TRUE}
eia_series(api_key = api_key,
series_id = c("NG.RES_EPG0_R5302_SND_BCF.A", "NG.RES_EPG0_R5302_SMT_BCF.A"),
tidy_data = "tidy_long",
only_data = TRUE)
```