quandl/R-package — pull request #2 by daroczig (2013-03-05 13:55:30+00:00)
Title: Ditching XML for JSON for imporved speed and 50% less query to Quandl servers

What I did not like in the prior implementation is that the `Quandl` function was querying the servers twice:
* once to check if the data exists and to identify frequency,
* then really fetched data.

I wanted to merge these two process, but `XML` parsing seems to be really slow compared to `JSON`, which latter tends to have smaller size too. So suggesting to drop `XML` for the really fast parser of `RSJONIO`.

I have made a quick comparison of the two methods:

```rout
> library(microbenchmark)
> Quandl.XML <- function() x <- Quandl("NSE/OIL")
> Quandl.JSON <- function() x <- Quandl2("NSE/OIL")
> microbenchmark(Quandl.XML(), Quandl.JSON(), times = 10)
Unit: milliseconds
expr min lq median uq max neval
Quandl.XML() 993.8316 1053.9598 1094.4323 1110.6291 1192.171 10
Quandl.JSON() 848.3522 895.3143 908.8844 945.8231 1024.257 10
```
![compare](https://f.cloud.github.com/assets/495736/221428/7d0da5b6-859b-11e2-8d6f-6f72c4a08b16.png)

So we can see some speed improvement, and also less load on your servers for sure.

---

Although I have tested the rewritten parts, it's without any warranty of course :)

Although there are some differences in the results of the functions:

```rout
> identical(Quandl("NSE/OIL"), Quandl2("NSE/OIL"))
[1] FALSE
```

That's just thanks to the column names, as `read.csv` forces safe names:

```rout
> Quandl.XML()
'data.frame':	857 obs. of 8 variables:
$ Date : Date, format: "2009-09-30" "2009-10-01" ...
$ Open : num 1096 1102 1152 1150 1154 ...
$ High : num 1157 1174 1166 1157 1161 ...
$ Low : num 1090 1102 1137 1132 1140 ...
$ Last : num 1135 1167 1143 1143 1141 ...
$ Close : num 1141 1166 1141 1145 1142 ...
$ Total.Trade.Quantity: num 19748012 3074254 919832 627957 698216 ...
$ Turnover..Lacs. : num 223877 35464 10581 7186 8033 ...
> Quandl.JSON()
'data.frame':	857 obs. of 8 variables:
$ Date : Date, format: "2009-09-30" "2009-10-01" ...
$ Open : num 1096 1102 1152 1150 1154 ...
$ High : num 1157 1174 1166 1157 1161 ...
$ Low : num 1090 1102 1137 1132 1140 ...
$ Last : num 1135 1167 1143 1143 1141 ...
$ Close : num 1141 1166 1141 1145 1142 ...
$ Total Trade Quantity: num 19748012 3074254 919832 627957 698216 ...
$ Turnover (Lacs) : num 223877 35464 10581 7186 8033 ...
```

This can be also done with the current method too, although I prefer to use human readable variable names :)

And of course feel free to ignore this pull request if you insist on using `XML`.