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

Geocode more precise #25

Closed
maelle opened this issue Nov 30, 2015 · 8 comments
Closed

Geocode more precise #25

maelle opened this issue Nov 30, 2015 · 8 comments

Comments

@maelle
Copy link

maelle commented Nov 30, 2015

I think it would be great to be able to get results for a precise part of a country if one knows the code for this region. E.g. "IN" is India and "IN-WB" is West Bengali, one could be interested in finding the results for "IN-WB".

@eddelbuettel
Copy link
Collaborator

That would be somewhat difficult. See the code and data in the package; you would have to unambiguously generalize to all world regions and sub-regions. This would have to start with a replacement countries data set, and new code.

Volunteers welcome.

@maelle
Copy link
Author

maelle commented Nov 30, 2015

Yes I agree that it is not easy to generalize. I have modified the code for my own needs but it's quite ugly. If I figure something better out I'll come back. :-)

@eddelbuettel
Copy link
Collaborator

Even if you have just a sketch, we could at least add it to the docs. Also worth noting that your suggestion already works -- which your initial post did not say :)

@maelle
Copy link
Author

maelle commented Nov 30, 2015

Yep sorry. But my sketch only returns the table with week and number of searches (not the other information). I modified the gtrends.R code (I hope the text is attached) so that it returns the string sooner and does not check countries. So at one point I have
vec <- strsplit(resultsText, "\n{2,}")[[1]]
return(vec[2])
gtrends.txt

Then I modify the string
dataSearch <- gtrends(query=query, geo=paste("IN-", code, sep=""), res="week",
start_date=as.Date("2012-12-31"))
dataSearch <- strsplit(dataSearch, "\n")
dataSearch <- lapply(dataSearch, strsplit, ",")
dataSearch <- unlist(dataSearch)
dataSearch <- dataSearch[4:length(dataSearch)]
dataSearch <- unlist(lapply(dataSearch, strsplit, " - "))
date1 <- lubridate::ymd(dataSearch[c(TRUE, FALSE, FALSE)])
interest <- as.numeric(dataSearch[c(FALSE, FALSE, TRUE)])

So really it's not a nice code right now.

I do not even know where to find a list of all subregions codes? Where did you find the table for all countries?

Anyway thanks a lot for the package, I'm glad it exists!

@maelle
Copy link
Author

maelle commented Dec 1, 2015

Thanks, I'll try to have a look at that!

eddelbuettel added a commit that referenced this issue Feb 18, 2016
support for more precise geocode (closes #25)
@maelle
Copy link
Author

maelle commented Feb 18, 2016

Awesome!!!

@PMassicotte
Copy link
Owner

:)

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

No branches or pull requests

3 participants