The first think you need to do is to download tweets. You need to Setup your tweeter account. Much Information can be found in Internet on how to do it. The following two links were useful for my Setup (last checked in May 2017)
In particular I found the following two links useful (last checked in May 2017):
You will need the following R packages
library("devtools")
library("twitteR")
library("ROAuth")
Supposing you have your keys You have to run the following code
api_key <- XXXXXXXXXXXXXXXXXXXXXX
api_secret <- XXXXXXXXXXXXXXXXXXXXXX
access_token <- XXXXXXXXXXXXXXXXXXXXXX
access_token_secret <- XXXXXXXXXXXXXXXXXXXXXX
setup_twitter_oauth(api_key,api_secret)
Change XXXXXXXXXXXXXXXXXXXXXX
to your keys (if you have Setup your tweeter account you know which keys I mean).
Let's now suppose we want to download tweets on coffee. The following code will do it
search.string <- "#coffee"
no.of.tweets <- 1000
c_tweets <- searchTwitter(search.string, n=no.of.tweets, lang="en")
You will get 1000 tweets on "coffee".