Gustavo Gustavo - 1 month ago 5
R Question

Error importing SDMX data into R

The problem happens when I am trying to import OECD data. For example, if I try the following code:

library(rsdmx)
data.url <- "http://stats.oecd.org/restsdmx/sdmx.ashx/GetData/QNA/AUS.B1_GE+P3+P31S14_S15+P3S13+P5+P51+P52_P53+P52+P53+B11+P6+P61+P62+P7+P71+P72+RB1_GE+PPPGDP+P41+P3_P51+P3_P5.CQRSA.Q/all?startTime=2011-Q1&endTime=2015-Q2"
my.sdmx <- readSDMX(data.url)


I get the following error

<XMLInputError: XML content does not seem to be XML: '<message:MessageGroup xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic" ...


However, this only seems to happen with OECD data. If I replace
data.url
above with

data.url <- "http://data.fao.org/sdmx/repository/data/CROP_PRODUCTION/.156.5312../FAO?startPeriod=2008&endPeriod=2008"


then the code runs smoothly. It also works if I download the XML file and parse it using
readSDMX('file.xml', isURL=FALSE)
.

I wonder if this has anything to do with the '' characters that show up when parsing OECD XML, and if there is a way to fix this.

Answer

There has been some recent changes in OECD portal. One of them was that the web requests did not return a valid xml response. The few characters you mentioned correspond to the Bytes Order Mark (BOM). A control has been added very recently in rsdmx to manage properly such BOM, change that has also been reflected in CRAN. Upgrading to rsdmx 0.4-7 will solve your issue.

Comments