Function to query and extract data from the EIA API v2
eia_get(
api_key,
api_path,
data = "value",
facets = NULL,
start = NULL,
end = NULL,
length = NULL,
offset = NULL,
frequency = NULL,
format = "data.frame"
)
A string, EIA API key, see https://www.eia.gov/opendata/ for registration to the API service
A string, the API path to follow the API endpoint https://api.eia.gov/v2/. The path can be found on the EIA API dashboard, for more details see https://www.eia.gov/opendata/browser/
A string, the metric type, by default uses 'value' (defined as 'data' on the API header)
A list, optional, set the filtering argument (defined as 'facets' on the API header), following the structure of list(facet_name_1 = value_1, facet_name_2 = value_2)
A string, optional, set the starting date or time of the series using "YYYY-MM-DD" format for date and "YYYY-MM-DDTHH" format for hourly time series
A string, optional, set the ending date or time of the series using "YYYY-MM-DD" format for date and "YYYY-MM-DDTHH" format for hourly time series
An integer, optional, defines the length of the series, if set to NULL (default), will default to the API default value of 5000 observations per pull. The API enables a pull of up to 100K observations per call. If needed to pull more than the API limit per call, recommend to iterate the call with the use of the start, end and/or offset arguments
An integer, optional, set the number of observations to offset from the default starting point of the series. If set to NULL (default), will default to the API default value of 0
A string, optional, define the API frequency argument (e.g., hourly, monthly, annual, etc.). If set to NULL (default), will default to the API default value
A string, defines the output of the return object to either "data.frame" (default) or "data.table"
data.table/data.frame object
if (FALSE) {
# Required an EIA API key to send a query
api_key <- "YOUR_API_KEY"
df <- eia_get(
api_key = api_key,
api_path = "electricity/rto/fuel-type-data/data/",
data = "value"
)
}