Simple R package for UN Comtrade API

This post has moved to https://read.stefanangrick.net/simple-r-package-for-un-comtrade-api. Please update your bookmarks.

9 comments to Simple R package for UN Comtrade API

  • Guillermo

    Hi! One question (sorry if it is too basic): once the data is extracted, how can I get a data frame out to it? Or, how can I save it as a CSV file? Thank you very much. Best, Guillermo

  • Kush

    Thanks for writing this package. I could not export s1 to a csv file using write.csv. It would be great if you could a couple of lines that show to either convert s1 to a dataframe or to export it as a csv file

    write.csv(s1)
    Error in data.frame(validation = NULL, data = list(Classification = c(1L, :
    arguments imply differing number of rows: 0, 6

    Thanks!

  • Xiaofeng

    Thank you very much for your work! How can I get the hs6 product-based data (six digits) data from get.Comtrade()?

    Specifically, I want to get the product (hs6 code: 880211) trade data between 842 (partner) and 642 (reporter). But I cannot an error from get.Comtrade(r = “642″, p = “842″, px=”880211″).

    How can I get the data?

    Thanks !

    • stefan.a

      Hi Xiaofeng! As I wrote, I simply just copied the sample code from UNCTAD and packaged it, so I’d suggest you check out their homepage for some example calls to their API. I think you have to use the parameter “px” to specify the classification code you want to use (e.g. “H4″ for HS 2012), and the parameter “cc” to supply the specific product code you’re looking for, but I haven’t had time to try this myself. Have a look at this website for a more detailed explanation of what each parameter value stands for.

      Good luck!

  • Meghna

    Hi Stefan,
    Thank you for this! It is very useful! I just have one question. I am trying to extract data for all HS6 commodities exported from all countries to the rest of the world for the year 1992. However, even using your package I get a return that says “Result too large” My requested result set count is 399004. Is there a way for me to define the country ids into 4/5 sets and get the results for each set separately?
    Thank you for your time!

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>