Creating a Simple R Package for Accessing the UN Comtrade API

I've recently been working a lot with R, a statistical programming language, and have built up a small collection of functions that I use regularly. One tool I've come to rely on is a function to obtain data from the United Nations' Comtrade database, an excellent resource for country-to-country trade statistics. Since there was no existing R package to access their new API (which is still in beta), I created my own function based on the sample code provided on their homepage and kept it in my personal files. I decided to package 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

This package is identical to the sample code on the UN homepage with added documentation. Note that the UN is saying their API might change, and since I'm not planning to keep this updated (for now, at least), there's a chance the package could stop working in the future. But for now, here's how to get it up and running in R:

download.file(url = "https://media.portblue.net/resources/150429_uncomtrade-r-package/comtrade.tar.gz", destfile = "comtrade.tar.gz")
library(tools)
md5sum("comtrade.tar.gz")

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

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