Site icon R-bloggers

Setting up the Twitter R package for text analytics

[This article was first published on Big Computing, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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.

library(twitteR)

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 http://twitter.com/signup 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 https://apps.twitter.com 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 https://bigcomputing.blogspot.com. 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

n

To leave a comment for the author, please follow the link and comment on their blog: Big Computing.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.