eflores89 eflores89 - 1 month ago 13
R Question

Reading SDMX in R - parse error?

I've been trying to develop a shiny app in R with INEGI (mexican statistics agency) data through their recently initiated SDMX service. I went as far a contacting the developers themselves and they gave me the following, unworkable, code:

require(devtools)
require(RSQLite)
require(rsdmx)
require(RCurl)

url <- paste("http://www.snieg.mx/opendata/NSIRestService/Data/ALL,DF_PIB_PB2008,ALL/ALL/INEGI");
sdmxObj <- readSDMX(url)

df_pib <- as.data.frame(sdmxObj)


Which brings me to the following errors:

sdmxObj <- readSDMX(url)
Opening and ending tag mismatch: ad line 1 and Name
Opening and ending tag mismatch: b3 line 1 and Name
Opening and ending tag mismatch: b3 line 1 and Department
Opening and ending tag mismatch: c3 line 1 and Contact
Opening and ending tag mismatch: a1 line 1 and Sender
Opening and ending tag mismatch: c3 line 1 and Header
Opening and ending tag mismatch: b3 line 1 and GenericData


... etc, you get the point.

I tried to use another url (maybe this was to broad, bringing in every GDP measurement), but I get the same result:

url<-"http://www.snieg.mx/opendata/NSIRestService/Data/ALL,DF_PIB_PB2008,ALL/.MX.........C05.......0101/INEGI?format=compact"


If I download the file directly with my browser I seem to be getting useful structures.

Any ideas? Does this seem like a faulty definition directly from the source or an issue with the package "rsdmx", if so, has anyone found a way to parse similar structures correctly?

Answer

You could try RJSDMX .

To download all the time series of the DF_PIB_PB2008 dataflow you just need to hit:

library(RJSDMX)
result = getSDMX('INEGI', 'DF_PIB_PB2008/.................')

or equivalently:

result = getSDMX('INEGI', 'DF_PIB_PB2008/ALL')

If you need time series as a result, you're done. Elseway, if you prefer a data.frame, you can get it calling:

dfresult = sdmxdf(result, meta=T)

You can find more information about the package and its configuration in the project wiki