Getting ready

First, sign up for a Twitter developer account (https://apps.twitter.com) 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:

install.packages(c("twitteR","RColorBrewer","plyr","ggplot2","devtools","httr"))require(devtools)

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("https://cran.r-project.org/src/contrib/Archive/Rstem/Rstem_0.4-1.tar.gz")install_url("https://cran.r-project.org/src/contrib/Archive/slam/slam_0.1-37.tar.gz") ...

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.