0

I want to make a Twitter search, specifying the location. I am using the rtweet package. However, when I print the 'lookup_coords' function for the country of Venezuela or the city of Caracas, there are no results. I have followed all advices from previous posts and nothing have helped. I have my own Google Api Key I am working on R, Windows 7.

Is there any possibility to self define the coordinates and assign it to the 'search_tweets' function? How do I know which is the proper syntax for naming every city or country in the world? Is there a list somewhere?

lookup_coords(address = "Venezuela", components = "country:Venezuela", apikey = "XXXXXXX")

the result is:

$place
[1] "Venezuela"

$box
NULL

$point
NULL

attr(,"class")
[1] "coords" "list" 

when I check the API, all works fine:

identical(Sys.getenv("GOOGLE_MAPS_KEY"),rtweet:::find_google_geocode_key())
[1] TRUE
delViento
  • 157
  • 8
  • You can try using another geocoding function. With `tmaptools` package you can do `geocode_OSM("caracas")`. [Here's](https://cran.r-project.org/web/packages/tmaptools/tmaptools.pdf) the package documentation – patL Jul 30 '19 at 10:22
  • When I do that I get the following error: "Error in rt[[i]] : subscript out of bounds" `> geocode_OSM("caracas") $`query` `[1] "caracas" $coords x y -66.9146 10.5061 $bbox xmin ymin xmax ymax -67.0746 10.3461 -66.7546 10.6661 ` – delViento Jul 31 '19 at 09:51
  • `ccs_coord <- geocode_OSM("caracas")` `search_CCS_basura <- search_tweets("gobierno", n=no.of.tweets, lang="es, include_rts = FALSE, retryonratelimit = TRUE, token = token, lookup_coords = ccs_coord$coords) ` – delViento Jul 31 '19 at 11:41
  • I do the previous and I get the error: "Error in rt[[i]] : subscript out of bounds" – delViento Jul 31 '19 at 11:44
  • That's because the output from `geocode_OSM` is different from `lookup_coords`. You can try changing output names. For example: `coord_caracas %<>% purrr::set_names("place", "point", "box")` and then, `names(coord_caracas$point) <- c("lng", "lat")`. Let me know if it works. – patL Jul 31 '19 at 12:21
  • I really tried, but I get still the same error. Also I didn't manage to reorder the components of the list `ccs_coord <- geocode_OSM("caracas")` `names(ccs_coord) <- c("place", "point", "box")` `names(ccs_coord$point) <- c("lat", "lng")` This doesnt work as well: `ccs_coord <- ccs_coord[order(c("`place`", "box", "point"))]` – delViento Jul 31 '19 at 14:28
  • That's because `lookup_coords` argument on `search_tweets` uses function with same name, that requires a character instead of a numeric vector of coordinates. One option is trying to get all tweets you want, and filter by country: `rt %>% filter(country %in% "Venezuela")` (this returns me a tibble with 213 rows. – patL Aug 01 '19 at 09:48

0 Answers0