How to scrape only tweets with lat_lon (geocode) information in R

Viewed 24

I'm scraping tweets by using the rtweet package in R. As I'm interested in getting only tweets who bring with them the information about lat and long (geocode) about a specific location, I use the google Api and the lookup_coords function to get the coordinates of the specified location.

Usually I do like this:

db <-  search_tweets(q = "xxx", n= 1000, lang = "it",
                geocode = lookup_coords("Italy", apikey = apiKey)

and then to filter and remove tweets without lat and lon I do this way:

db_tweets <- lat_lng(db) 
db_tweets.geo <- db_tweets %>%
                filter(is.na(lat) == FALSE & is.na(lng) == FALSE)

In order to make the last step more efficient I would like to set a filter while scraping tweets with search_tweets function, so that I can get only tweets with lat long information, but I'm not sure how to do this. Do you have any suggestion?

0 Answers
Related