Getting ready

First, sign up for a Twitter developer account ( and create a sample application to generate API keys and credentials under the Keys and Access Token tab, which we will require later to fetch real-time data from Twitter.

Then install the following packages:


The packages sentiment, Rstem, and slam are not available for direct installation in R (version 3.2 or higher), so you need to install it from source using the following command in the R console:

install_url("")install_url("") ...

Get R Data Analysis Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.