Setting up the Twitter R package for text analytics

February 23, 2016

(This article was first published on Big Computing, and kindly contributed to R-bloggers)

The Twitter R package by Jeff Gentry is a great way to get started in Text Analytics. This tutorial is about how to get setup to pull twitter data into R so that you can do some text analytics with it. Basically it is only the first step of getting data in a text analytics Workflow. I should also give a shout out here to Ted Kawartler for getting me interested in learning more about text analytics.

The first thing you need to do is downloadd the twitteR package and make it available in your R session.


Now on the Twitter side you need to do a few things to get setup if you have not done them already. I will go through this step by step so no one gets lost. It drives me crazy when people go too fast on the setup so I can’t use the tool.

You need to have a twitter account. if you do not have one go to and set one up. Also you need to have a modile number as part of this account.

Now that you have created a twitter account you need to go to and sign on with your twitter account.
Once you have signed in you should see the following screen, and simply click on the button that says “Create New App”.
Once you click on the “Create New App” button you will go to the Create an Application screen. There are three fields, a click box and a button you need to click on this page. The three fields are Name, Description and Website. The name of the application must be unique so this may take a few tries. The description needs to be at least 10 character long, and put in a website. If you do not have one you can use Now click the “Yes, I agree” box for the license agreement and click the “Create your Twitter application”.

Once you successfully create an appplication you will be taken to the application page. Once there click on the “key and access token” tab. From that page you are going to need four things.
1. Consumer Key (API Key)
2. Consumer Secret (API Secret)
click the “Create my access token” button.
3. Access Token
4. Access Token Secret
Now re-open your R session and enter the following code using those four pieces of information.
consumer_key <- “your_consumer_key”
consumer_secret <- “your_consumer_secret”
access_token <- “your_access_token”
access_secret <- “your_access_secret”

setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
Now you are set up on the Twitter side and the R side you should be ready to go. I will cover doing some basic data pulls from Twitter in my next post

To leave a comment for the author, please follow the link and comment on their blog: Big Computing. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)