Raspberry Pi Twitter Sentiment Analysis Server – Part 1

One of the most read blog posts I’ve done was “Twitter sentiment analysis in 30 seconds” and it’s still one of the most used search terms.

“Imperfection is beauty, madness is genius and it’s better to be absolutely ridiculous than absolutely boring.”

There was a reason I named the blog after a Marilyn Monroe quote, software and data are never perfect. It’s an imperfect medium. The curious nature of developers means that folk will think of you as mad from time to time, that’s okay with me.

So, I have a Raspberry Pi with the standard Raspian Wheezy distro on it. Now I’ve been pondering a dozen ideas but this seems a fun one to do for the sake of the blog, kudos and general mucking around. It is better to be ridiculous than boring….


Assuming you have the basic OS installed and a connection to the internet. I wired my direct to my MacBook Pro with a standard ethernet cable then I can ssh in from the terminal.

The Aim

First things first I want R to use the Twitter library to pull in the results of a Twitter search.  Using a modified version of the sentiment analysis R script then figure out whether a tweet is positive or negative in sentiment.

Another requirement is to store the most recent tweet ID somewhere so on the next run we only pick up tweets from that point onwards.  We’ll use cron to schedule R to run the script on a regular basis.

So, in this part we’ll just get the basics of everything installed.


There’s a few bits we need to install before we think about the Twitter library.

You’ll need libcurl4-gnutls-dev and libcurl4-openssl-dev installed as R/Twitter library require RCurl and ROauth to be installed.

So from the command line:

sudo apt-get install libcurl4-gnutls-dev
sudo apt-get install libcurl4-openssl-dev

Next we install R itself, we only need the base install.

sudo apt-get install r-base-core

Now we can open R and install the Twitter library.

From the command line:


This will then give us the R shell.

>install.packages("twitteR", dependencies=TRUE)

This will install the package to read Twitter stuff.  This may take some time as it will download all the required packages and install them too.  You’ll know when you’re done when you see something along the lines of:

* DONE (twitteR)
The downloaded source packages are in

To load the library type the following:

> library(twitteR)

This will load in the required libraries ready for use.

Loading required package: ROAuth
Loading required package: RCurl
Loading required package: bitops
Loading required package: digest
Loading required package: rjson

Now since the original blog post the Twitter library now follows Twitter’s API 1.1 which means that most requests will need OAuth authentication.  So that’s the next job but I’m saving that for the next part of the series.

2 responses to “Raspberry Pi Twitter Sentiment Analysis Server – Part 1”

  1. How can one install both libcurl4-openssl and libcurl4-gnutls? Apt tries to uninstall one every time I try to install the other

  2. The instructions I originally posted worked fine but now I’m not doing anything else Raspberry Pi based (I donated the gear to somewhere that was going to use it). So I’m sorry I can’t help you any further.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: