R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(EIAdata)
Loading required package: XML
Loading required package: plyr
Loading required package: xts
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/EIAdata/getCatEIA.Rd_%03d_medium.png", width=480, height=480)
> ### Name: getCatEIA
> ### Title: A function to view the sub and parent categories of an Energy
> ### Information Administration (EIA) API data category.
> ### Aliases: getCatEIA
>
> ### ** Examples
>
>
> ## 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)
+ }
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)
}
>
>
>
>
>
> dev.off()
null device
1
>