opensdmx/rsdmx

Reading IMF with readSDMX

NerijusC opened this issue · 4 comments

Sir,

I am trying to read DSD and data files from IMF. I am interested in National accounts (id NAG), which I found when looking at the data flow definitions.

 dsd <- readSDMX(providerId = "IMF", resource = "dataflow")
 as.data.frame(dsd)

However, typing the following code returns an error:

readSDMX(providerId = "IMF", resource = "datastructure", 
           resourceId =   "NAG")

Error
[rsdmx][INFO] Fetching 'https://sdmxcentral.imf.org/ws/public/sdmxapi/rest/datastructure/IMF/NAG/latest/?references=children'
Not Found (HTTP 404).Error in readSDMX(providerId = "IMF", agencyId = "IMF", resource = "datastructure", :
HTTP request failed with status: 404

How to solve this? More generally, perhaps you know the best way to upload data from IMF to R? I have not found an easy way to do this yet.

Sincerely,
NerijusC

@NerijusC the first request you did gives you the list of dataflows available:

 dataflows.sdmx <- readSDMX(providerId = "IMF", resource = "dataflow")
 dataflows <- as.data.frame(dataflows.sdmx)

Check the above dataflows data.frame, you will see a column dsdRef. Sometimes in SDMX, the dsdRef doesn't match the dataflow ID. This is the case when various dataflows share the same data structure definition. You are looking for the datastructure definition of the 'NAG' dataflow. Its dsdRef is "ECOFIN_DSD".

Try this then, and it will work:

dsd = readSDMX(providerId = "IMF", resource = "datastructure", resourceId = "ECOFIN_DSD")

To query data, you can look at this example: https://github.com/opensdmx/rsdmx/blob/master/tests/testthat/test_Main_Helpers.R#L139

Dear Emmanuel,

Thank you so much for this. DSD works fine now. However, the data pull is still not working. I tried your example as well as the NAG one, but I get an error.

  readSDMX(providerId = "IMF", resource = "data", flowRef = "BOP_GBPM6", start = 2010, end = 2015) 
  readSDMX(providerId = "IMF", resource = "data", flowRef = "NAG")

[rsdmx][INFO] Fetching 'https://sdmxcentral.imf.org/ws/public/sdmxapi/rest/data/BOP_GBPM6/all/all/?startPeriod=2010&endPeriod=2015'
Not Found (HTTP 404).Error in readSDMX(providerId = "IMF", resource = "data", flowRef = "BOP_GBPM6", :
HTTP request failed with status: 404

i'll check ASAP

I'm afraid that data access has been restricted (although I don't get the appropriate http error for that). See https://sdmxcentral.imf.org/webservice/data.html You may contact IMF for support.