Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing country: "NA" #202

Closed
ucb opened this issue Jun 23, 2017 · 8 comments
Closed

Missing country: "NA" #202

ucb opened this issue Jun 23, 2017 · 8 comments

Comments

@ucb
Copy link

ucb commented Jun 23, 2017

It may sound like a pun, but "NA" is Namibia and works fine with Google website.

Error: Country code not valid. Please use 'data(countries)' to retreive valid codes

@PMassicotte
Copy link
Owner

I will try to explore the problem this week.

@racorreia
Copy link

racorreia commented Oct 7, 2018

I ran into the same problem as @ucb and decided to have a look at the issue. I managed to solve it eventually, with a cheap workaround...

The first step is replacing the Namibia country code in data(countries) from logical to character. This needs to be changed in the sysdata as well, otherwise gtrends won't recognize it and will return the same error code.

A second step is necessary in the get_widget function. The issue is that Namibia's country code gets converted to logical NA from JSON, thus causing problems with the functions that depend on it. However, by strategically replacing the content of widget in the columns referring to the country code, I was able to get the correct structure required to run the remaining functions and it seems to return the same data as the website. If people are looking for a simple workaround for this issue, you can add the following lines at the end of the get_widget function:

widget <- myjs$widgets
  
  #Correction for Namibia
  if(token_payload$comparisonItem$geo=="NA"){
    widget$request$comparisonItem[[1]]$geo$country<-"NA"
    widget$request$geo$country[2]<-"NA"
    widget$request$restriction$geo$country[3:4]<-"NA"
    widget$geo[2]<-"NA"
  }
  
return(widget)

There might be a more elegant solution, but I wasn't able to come up with any...

Hope this helps @PMassicotte and thanks for the great work on the package!

@racorreia
Copy link

Another update, as I just noticed that Kosovo (country code "XK") is also missing from the countries list. An entry for Kosovo is present, but it has the Macedonia (FYROM) code "MK". Either changing this or adding a new line for Kosovo specifically, in both countries.rda and sysdata.rda will solve the issue.

@PMassicotte
Copy link
Owner

PMassicotte commented Oct 10, 2018

The best way to do it is programmatically. Should check if the list we are using has been updated.

https://raw.githubusercontent.com/CharlotteWoolley/Comprehensive_ISO_Location_Codes/master/ISO_codes.csv

@racorreia
Copy link

Sure. I wasn't certain where the data came from and wanted to find a quick fix, so that did the trick. However, I checked the link you shared and there has been no change for Kosovo.

Either way, thanks for the great work!

@PMassicotte
Copy link
Owner

More than happy to include an updated version of data if you can find a reliable source!

@racorreia
Copy link

The issue seems to be that ISO still hasn't officially assigned a code to Kosovo. The issue is more or less explained here: https://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/

XK was assigned as a temporary code to Kosovo under UN Security Council resolution 1244/99 and Google seems to go with it, but it won't be in any "official" ISO country list given it has not officially recognized by ISO as of yet.

The code can be found in some country lists such as the WorldBank (see for example wb_api2c in package countrycode), but not in any ISO list that I could find...

@joachim-gassen
Copy link
Contributor

Just for the sake of completeness: The "NA" == NA issue seems to be caused by a corner case parsing problem in {jsonlite}. My patch #353 circumvents this problem and I also filed an PR with the {jsonlite} coordinator: jeroen/jsonlite#318

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants