eia_series: EIA data series

Description Usage Arguments Details Value See Also Examples

View source: R/series.R

Description

Obtain EIA data series.

Usage

1
2
3
4
5
6
7
8
9
eia_series(
  id,
  start = NULL,
  end = NULL,
  n = NULL,
  tidy = TRUE,
  cache = TRUE,
  key = eia_get_key()
)

Arguments

id

character, series ID, may be a vector.

start

start date. Providing only a start date will return up to the maximum 100 results if available.

end

end date. Providing only an end date will a single result for that date.

n

integer, length of series to return ending at most recent value or at end date if also provided. Ignored if start is not NULL.

tidy

logical, return a tidier result. See details.

cache

logical, cache result for duration of R session using memoization. See details.

key

API key: character if set explicitly; not needed if key is set globally. See eia_set_key.

Details

By default, additional processing is done to return a tibble data frame. Set tidy = FALSE to return only the initial list result of jsonlite::fromJSON. Set tidy = NA to return the original JSON as a character string.

Set to cache = FALSE to force a new API call for updated data. Using FALSE always makes a new API call and returns the result from the server. TRUE uses memoization on a per R session basis, caching the result of the function call in memory for the duration of the R session. You can reset the entire cache by calling eia_clear_cache().

Value

a tibble data frame (or a list, or character, depending on tidy value)

See Also

eia_clear_cache

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
# use eia_set_key() to store stored API key
id <- paste0("ELEC.GEN.ALL-AK-99.", c("A", "Q", "M"))

x1 <- eia_series(id[1], start = 2016)
x2 <- eia_series(id[2], n = 5)
x3 <- eia_series(id[3], end = 2016, n = 5)
x1$data[[1]]
x2$data[[1]]
x3$data[[1]]

# multiple series counted as a single API call
x <- eia_series(id, end = 2016, n = 2)
x$data

## End(Not run)

eia documentation built on Feb. 22, 2021, 9:09 a.m.