searchTwitter example in R for #shark

Code has comments for explanation.
Geocodes can be obtained here (batch also available):  http://geoservices.tamu.edu/Services/Geocode/Interactive/

(TWITTER via uncccoder)

install.packages(c("devtools", "rjson", "bit64", "httr"))
library(devtools)
#you will need twitteR package
require(twitteR)
api_key<- "your api key"
api_secret<-"your api secret"
access_token<-"your access token"
access_token_secret<-"your access token secret"
setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)
sharktweets = searchTwitter("shark attack",since='2015-06-01')
# after running the code you can enter commands to see the text
head(sharktweets,2)
# try with trends - this may not be useful as it is restricted to trend locations
# not sure if this can be extended
# woeid is a numerical identification code
# describing a Yahoo Where on Earth ID
# or you can use lat and long
# lookup here http://woeid.rosselliot.co.nz/
# first try out sample code with trends
Locs <- availableTrendLocations()
LocsUSA = subset(Locs, country == "United States")
woeidAtlanta = subset(LocsUSA, name == "Atlanta")$woeid
trends = getTrends(woeidAtlanta)
#another easier example from R bloggers
#more examples from http://www.r-bloggers.com/?s=Twitter
#searchTwitter is another useful function
#here we are searching Southport with 50 mile radius
# you can look up geocodes here http://geoservices.tamu.edu/Services/Geocode/Interactive/
rdmTweets <- searchTwitter('#shark', n=500, geocode='33.9405664680941,-78.0191985828112,50mi')
#Create a dataframe based around the results
df <- do.call("rbind", lapply(rdmTweets, as.data.frame))
#Here are the columns
names(df)
#And some example content
head(df,3)
#more examples from http://www.r-bloggers.com/?s=Twitter
View(df)
# just for fun
# examine tweets near Myrtle Beach
rdmTweets <- searchTwitter('#shark', geocode='35.3662481025765,-79.4293938606862,100mi',
                           since='2016-06-01', until='2016-07-05')
#Create a dataframe based around the results
df2 <- do.call("rbind", lapply(rdmTweets, as.data.frame))
#Here are the columns
names(df2)
#And some example content
head(df2,3)
#more examples from http://www.r-bloggers.com/?s=Twitter
View(df2)
#
#now for Topsail Island
#
rdmTweets <- searchTwitter('#shark', geocode='35.3662481025765,-79.4293938606862,100mi',
                           since='2016-06-01', until='2016-07-05')
#Create a dataframe based around the results
df3 <- do.call("rbind", lapply(rdmTweets, as.data.frame))
#Here are the columns
names(df3)
#And some example content
head(df3,3)
#more examples from http://www.r-bloggers.com/?s=Twitter
View(df3)
#
#now for Nags Head
#miles changed to 10
rdmTweets <- searchTwitter('#shark', geocode='35.9468685604644,-75.6266474452463,100mi',
                           since='2016-06-01', until='2016-07-05')
#Create a dataframe based around the results
df4 <- do.call("rbind", lapply(rdmTweets, as.data.frame))
#Here are the columns
names(df4)
#And some example content
head(df4,3)
#more examples from http://www.r-bloggers.com/?s=Twitter
View(df4)