Collecting tweets based on csv file with point coordinates

Hi,

I am new to R so I am sorry for any non-well formulated question.
I have a csv file with coordinates of points corresponding to places scattered around London and I want to collect people tweets in these locations to see how many people there are in each place.

I cannot find a code which shows where I should insert the imported file with coordinates so that I can run a query and select only tweets in those coordinates.

Thanks!

rtweet::search_tweets has a geocode parameter that may do what you want:

http://rtweet.info/reference/search_tweets.html

Also see hrbrmstr's book about rtweet, which includes step-by-step instructions for getting started and sorting out tokens and such:

2 Likes

Thanks Alistaire.

I have used this code:

hrc <- search_tweets("any", n = "1000", geocode = "-0.072841, 51.514047, 10me")

and got the following:
Error: could not find function "search_tweets"

Plus, I have 5,000 coordinate points (in a csv file) so is there a way to automatically insert all of them as geocode? it would be impossible to do it manually. The problem is that I have scattered places around, not just one big area with boundaries.

I also thought of extracting all the tweets I get from outdoor spaces in London and then clip the data to my coordinatesin QGIS, but I must find the right keyword to look for tweets.

Did you install and attach/load the rtweet library?
http://rtweet.info/

Thank you Mara.

I did install it and load it usign the following codes:

install.packages(rtweet)
library(rtweet)

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

Right now the best way to install reprex is:

# install.packages("devtools")
devtools::install_github("tidyverse/reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ, linked to below.

Thanks a lot Mara!

Since my script includes secret tokens, I will copy it here masking the codes:

> setwd("") # does it have to be a folder in my pc or the website I have created when making a twitter app?

> source("https://urbanstudiesresearch.blogspot.com\") #this would be the website I have created

> install.packages("twitteR")
> library(twitteR)

> consumer_key <-""
> consumer_secret <-""
> access_token <- ""
> access_secret <- ""

> setup_twitter_oauth("consumer_key","consumer_secret","access_token", "access_secret")
> Yes

> hrc <- search_tweets("square", n = "1000", geocode = "-0.072841, 51.514047, 10me")

If I run the >source command first, I immediately get the first error:
Error: unexpected symbol in:
"source("https://urbanstudiesresearch.blogspot.com")

Couple things:

  1. Do you really want to be using source() the R function in this way?
  1. You've installed and attached the twitteR package, not the rtweet package, which is why you wouldn't be able to use rtweet::search_tweets.
1 Like

-.- ... thank you!!

I am really new to r...