In searching for ways how to maximize data analysis capabilities in social media analytics offered by R particularly how to scrap data from Twitter, I stumbled upon a post on how to create a Twitter Bot in R by Automated Data Collection with R. Inquisitive to put this into action, I rolled my sleeves and delved into the challenge.
I crafted my Bot according to the author’s Bot which motivates PhD students to return to work by barking orders using mild insults.
In the same suit, I created three Microsoft Excel workbooks to act as database storage for phrases.
The first step was to install the XLConnect library that allows Excel worksheets support for R based script. This was followed by loading the MS Excel sheets and printing the stored phrases to ensure the XLConnect library functions.
The first bug I encounter reveals an output error of an unused argument within the XLConnect library (the unused argument being simply=T). After a few minutes, I realize it is typing error, instead of using the correct arguments simplify, I wrote simply.
After solving the typo error, the script is able to print out the phrases from our MS Excel sheets. The next step is to repeat the same procedure and print out words and insults from other MS Excel sheets. In essence, the Bot is a troll Bot aimed at tweeting trolling tweets which are somewhat insulting. We then combine our phrases to make clear sentences with help from the stringr package.
The next stage involves connecting to the Twitter API which proved to be the most challenging section of the script. All errors point to an error in my Oauth authentication setup.
Yet another error!!
Is there an end to this ??
After much deliberation, I had to make small changes to the code such as removing certain arguments and unnecessary parentheses as well additional packages such as XML and ROauth.
Finally the script was able to send a tweet.
Take note of the comparisons below to observe the difference between the earlier and recent versions of the script.
This is the complete working code.