Code Monkey home page Code Monkey logo

Comments (7)

ChrisMuir avatar ChrisMuir commented on June 15, 2024 2

FYI @jugdemon , API is back up and running.

from comtradr.

jugdemon avatar jugdemon commented on June 15, 2024 1

Good to know that it is not just me. In the meantime I used the manual interface of the worldbank to comtrade to download excel files with the necessary information. Apparently, they still have access (or more likely they run a replica). It looks like a cool package and I will use it the next time I have to access comtrade.

from comtradr.

jugdemon avatar jugdemon commented on June 15, 2024

A quick question, could it be, that the upgrade has rendered comtradr not working? When I make any queries, they always return empty (also on the comtrade.un.org).

from comtradr.

ChrisMuir avatar ChrisMuir commented on June 15, 2024

Ah, yeah that's interesting, I had no idea the API was down, thank you for bringing it to my attention. I'm not sure what's causing it. It's odd that their online data interface doesn't indicate the service being down or anything like that.

I'll keep my eyes on this, if the outage persist for more than today I will send them a bug report email asking what's going on.

Thanks!

from comtradr.

wallacemp avatar wallacemp commented on June 15, 2024

Hello Chris Muir,

I did not find a specific topic for my question. I would like to know if there is any command in comtradr to use country codes instead of the country names in the ct_search command.

Thank you for understanding

from comtradr.

ChrisMuir avatar ChrisMuir commented on June 15, 2024

Hello @wallacemp , nope the query function ct_search() does not support passing country codes as input. You can, however, create your own wrapper function, like I've demoed below, that will allow you to pass in country codes, and will convert the inputs to their character country names prior to calling ct_search(). Be aware, this is a super hacky fix, it uses comtradr:::get_country_db(), which is an undocumented non-exported function. Also, there are no checks to ensure the input ints are valid country codes, although you could easily add those checks to the wrapper function below. Hope this is helpful!

ct_search2 <- function(reporters, partners, ...) {
  
  if (!is.character(reporters)) {
    reporters <- as.character(reporters)
  }
  if (!is.character(partners)) {
    partners <- as.character(partners)
  }
  
  country_df <- comtradr:::get_country_db()
  
  reporters <- vapply(reporters, function(x) {
    country_df[country_df$code == x &
                 country_df$reporter == TRUE, ]$country_name
  }, character(1), USE.NAMES = FALSE)
  
  partners <- vapply(partners, function(x) {
    country_df[country_df$code == x &
                 country_df$partner == TRUE, ]$country_name
  }, character(1), USE.NAMES = FALSE)
  
  return(comtradr::ct_search(reporters, partners, ...))
}
df <- ct_search2(reporters = 156, 
                 partners = c(276, 288, 392, 484), 
                 trade_direction = "imports", 
                 start_date = 2010, 
                 end_date = 2014)
dim(df)
#> [1] 20 35

The example above is equivalent to doing:

df <- ct_search(reporters = "China", 
                partners = c("Germany", "Ghana", "Japan", "Mexico"), 
                trade_direction = "imports", 
                start_date = 2010, 
                end_date = 2014)

from comtradr.

datapumpernickel avatar datapumpernickel commented on June 15, 2024

Closing this issue, as changes will be adressed in planned relaunch. #45

from comtradr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.