I spent the majority of the most recent presidential debate thinking of a fun #rstats project. I had three objectives for the post:
(1) that it be fun to do; (2) that it showcase some functionality of
rcanvas; and (3) that it be interesting
to the public. The third objective was admittedly negotiable.
In the next two posts, I’m going to analyze the tweets from our US senators in response to #debate. Part I will show how to obtain each
senator’s twitter account with the
rcicero package, and Part II will perform some basic text analysis on the corpus of tweets with the awesome
rcicero requires some prep work before use which I’ve spelled out on the package’s GitHub README. Let’s
jump right in:
To get the twitter accounts, I needed a pair of longitude and latitude coordinates from each state, so I just grabbed
some from the
Get the Twitter Handles
Now I need to pass each pair of coordinates through the Cicero API with a custom function that gets each senator’s twitter account, and, just for fun, their party:
With our custom function in hand, it’s time to iterate with the
purrr package which is so beautiful and elegant, I can’t even bear to look at some of my old code. Warning: the code below is fairly expensive–it will run you about 59 Cicero API credits.
data.frame now has each senator’s last_name, first_name, twitter handle, and party:
Stay tuned for Part II.