2

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?

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
eflores89
  • 339
  • 2
  • 10
  • 27
  • As commented below, the rsdmx code you use is working fine. The problem is due to your workspace firewall. In addition, you don't need to add the other packages, only ``rsdmx`` is enought, which is maintained and available through CRAN repository.If you expect new functionalities in rsdmx, your suggestions are welcome: you can submit a ticket on https://github.com/opensdmx/rsdmx/issues or use the rsdmx mailing list. – eblondel Mar 19 '15 at 08:44

2 Answers2

2

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.

eblondel
  • 603
  • 4
  • 10
0

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

amattioc
  • 49
  • 4
  • Thanks, this seems correct but I keep getting a connection error even if using the code provided as an example in the wiki and package documentation. The error I get is: "Dataflow EXR not cached. Call Provider. " – eflores89 Feb 23 '15 at 15:55
  • That's not an error actually, but an informational message. It is actually not very clear. You should get the result anyway. If you get errors, just open an issue on github and I'll help you in the configuration. – amattioc Feb 23 '15 at 16:00
  • I think I figured out the error: my workplace firewall. Thank you, looks like a great and useful package. – eflores89 Feb 23 '15 at 16:21