Simple R package for UN Comtrade API

I have recently been doing a lot of work in R, a statistical programming language, and have started accumulating a small collection of functions that I regularly use. One of the tools I have particularly come to rely on is this function to obtain data from the United Nation's Comtrade database, a great source for country-to-country trade statistics. Since there seemed to be no R package that provides access to their new API (which is still in beta), I simply wrote a function for myself based on the sample code on their homepage and kept it with my personal files. Motivated by posts like this one, however, I decided to put the code into an R package and share it here for others to use.px.gif

You can get the source file here: comtrade.tar.gz, MD5 sum: 22ce86b845d8a8ec7af98b0377c5f885

The package is identical to the sample code on the UN homepage and simply adds documentation. Note that they say that their API may change at any point, and since I have no plans to keep this updated (for now, at least), this may simply stop working in the future. Nevertheless, here is how to set up the package directly from within R:

download.file(url = "", destfile = "comtrade.tar.gz") library(tools) md5sum("comtrade.tar.gz")

If the MD5 checksum corresponds to what you see above, go ahead and install the file and start pulling data from the UN using the get.Comtrade() function call:

install.packages("comtrade.tar.gz", repos = NULL, type = "source") library(comtrade) (s1 <- get.Comtrade(r = "842", p = "124,484"))

Originally published 29 April 2015.