Request data from EIA API version 2
request.Rd
Request data from EIA API version 2
Usage
eia2_req(
route = "",
facets = list(),
data_cols = character(),
frequency = NULL,
start = NULL,
end = NULL,
sort = data.frame(column = "period", direction = "desc"),
offset = 0,
length = 5000,
out = "json",
api_key = NULL
)
Arguments
- route
to base dataset
- facets
list of facet filter specifications
- data_cols
names of data columns to retrieve
- frequency
data frequency
- start
filter start of data requested
- end
filter end of data requested
- sort
data frame specifying sorting
- offset
starting position, for paged results
- length
number of data points to retrieve
- out
output data format, "json" or "xml"
- api_key
character api key, or NULL to omit
Examples
eia2_req("electricity")
#> <httr2_request>
#> GET
#> https://api.eia.gov/v2/electricity?sort%5B0%5D%5Bcolumn%5D=period&sort%5B0%5D%5Bdirection%5D=desc
#> Body: empty
#> Options:
#> • useragent: 'eia2 (http://github.com/jameelalsalam/eia2)'
#> Policies:
#> • error_body: a function
eia2_req("electricity/retail-sales")
#> <httr2_request>
#> GET
#> https://api.eia.gov/v2/electricity/retail-sales?sort%5B0%5D%5Bcolumn%5D=period&sort%5B0%5D%5Bdirection%5D=desc
#> Body: empty
#> Options:
#> • useragent: 'eia2 (http://github.com/jameelalsalam/eia2)'
#> Policies:
#> • error_body: a function
eia2_req("electricity/retail-sales/data")
#> <httr2_request>
#> GET
#> https://api.eia.gov/v2/electricity/retail-sales/data?sort%5B0%5D%5Bcolumn%5D=period&sort%5B0%5D%5Bdirection%5D=desc
#> Body: empty
#> Options:
#> • useragent: 'eia2 (http://github.com/jameelalsalam/eia2)'
#> Policies:
#> • error_body: a function
eia2_req("electricity/retail-sales/data", data_cols = "price")
#> <httr2_request>
#> GET
#> https://api.eia.gov/v2/electricity/retail-sales/data?data%5B0%5D=price&sort%5B0%5D%5Bcolumn%5D=period&sort%5B0%5D%5Bdirection%5D=desc
#> Body: empty
#> Options:
#> • useragent: 'eia2 (http://github.com/jameelalsalam/eia2)'
#> Policies:
#> • error_body: a function
eia2_req("electricity/retail-sales", data_cols = "price") # same as one above
#> <httr2_request>
#> GET
#> https://api.eia.gov/v2/electricity/retail-sales/data?data%5B0%5D=price&sort%5B0%5D%5Bcolumn%5D=period&sort%5B0%5D%5Bdirection%5D=desc
#> Body: empty
#> Options:
#> • useragent: 'eia2 (http://github.com/jameelalsalam/eia2)'
#> Policies:
#> • error_body: a function