A function to view the sub and parent categories of an Energy Information Administration (EIA) API data category.

Description

A function to view the sub and parent categories of a EIA API data category. The function will return Series IDs in a category if present.

Usage

1
getCatEIA(key, cat = 999999999)

Arguments

key

Your EIA API key, in quotes.

cat

An EIA API data category number.

Author(s)

Matthew Brigida

Examples

 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
## The function is currently defined as
function(key, cat=999999999){

  key <- unlist(strsplit(key, ";"))

  ifelse(cat==999999999,
         url <- paste("http://api.eia.gov/category?api_key=", 
		      key, "&out=xml", sep="" ),

         url <- paste("http://api.eia.gov/category?api_key=", 
		      key, "&category_id=", cat, "&out=xml", sep="" )
         )

  doc <- xmlParse(file=url, isURL=TRUE)

  Parent_Category <- tryCatch(xmlToDataFrame(nodes = 
	XML::getNodeSet(doc, "//category/parent_category_id")), 
        warning=function(w) FALSE, error=function(w) FALSE)

  Sub_Categories <- xmlToDataFrame(nodes = 
	XML::getNodeSet(doc, "//childcategories/row"))

  Series_IDs <- xmlToDataFrame(nodes = 
	XML::getNodeSet(doc, "///childseries/row"))

  Categories <- list(Parent_Category, Sub_Categories, Series_IDs)
  names(Categories) <- c("Parent_Category", "Sub_Categories", "Series_IDs")

  return(Categories)
}