eflores89
eflores89

Reputation: 359

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?

Upvotes: 2

Views: 367

Answers (2)

eblondel
eblondel

Reputation: 603

The code you pasted above, using rsdmx, works perfectly fine. The issue you had was about your workplace firewall, as you correctly figure out.

You only need to load rsdmx package (the other packages do not need to be explicitely declared)

require(rsdmx)

and do this code:

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)

I've checked for any potential issue related to this datasource, but there is not. Staying strictly within the scope of your post, your code is fine.

This being said, if you find a bug in rsdmx, you can directly submit a ticket at https://github.com/opensdmx/rsdmx/issues Prompt feedback is provided to users. You can also send suggestions or wished features there or in the rsdmx mailing list.

Upvotes: 2

amattioc
amattioc

Reputation: 49

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

Upvotes: 0

Related Questions