Create a twitter bot in the R programming language
0. You will need a twitter account
- Install R & RStudio
- Install Twitter Package (twitteR)
- Create a Twitter Application
- Create the R-Program to connect to twitter
- Schedule the R-Program to run on Task Manager
Download R and RStudio for Windows
In order to create a twitter bot you must first have the R-Programming language and R-studio installed.
1) Download R -Programming Language:
2) Download RStudio:
Install the twitteR Package
You will need the twitteR package to be able to connect to twitter and use some special functions for twitter. Just type the following command in your R-Studio. If you do not know how to install packages you can watch this video: https://www.youtube.com/watch?v=_-DFNLm3JeQ
twitteR: Provides an interface to the Twitter web API.
Create a Twitter Application
Sign in using your Twitter Account
You should’ve been directed to the twitter app. Now click “Create New App”
Create an application
NOTE: If you haven’t already, then you may need to add your phone number to your twitter profile. Go to settings and privacy→ Mobile
Go to Keys and Access Tokens
Write down the Consumer key (API Key) and the Consumer secret (API Secret)
Create your access token by clicking Create my access token
Once the access token is created, write down the Access Token and the Access Token Secret
Create the R-Program to connect to twitter
#Install and load the appropriate packages
#REPLACE '####' with the appropriate values from your twitter app
#Connect to twitter
#Extract Tweets !
searchTwitter("nba", n=3, lang="en")
#Post Tweet !
Contribute to R-Programs development by creating an account on GitHub.
Schedule the R-Program to run on Task Manager
Automating the tweets
Let’s automate our R program. I am using a Windows Operating System, so we can use Windows Task Scheduler, to schedule and automate our R-Program.
First we must open the Task Scheduler. You can go to your start button and in the search type “Task Scheduler” to open the program.
Right click on Task Scheduler Library and then right click on Task Scheduler Library.
Next click create task and give your task a name:
Then, under the Triggers tab choose your scheduling for the tweet. For example, you can make it daily, weekly, or monthly.
Finally, under the Actions tab you need to locate the file Rscript.exe for your installation of
R. This executable will be used to run your R program.
Mine was under “C:\R-3.1.2\bin\x64\Rscript.exe”. For Add Arguments choose the name of the
R script that you want to run. In the Start in , put the directory where the script is located.
That’s it your DONE !
Thanks for reading this article I hope its helpful to you all ! Keep up the learning, and if you would like more algorithm analysis videos please visit and subscribe to my YouTube channels (randerson112358 & compsci112358 )
Check Out the following for content / videos on Computer Science, Algorithm Analysis, Programming and Logic:
Video Tutorials on Recurrence Relation:
Video Tutorial on Algorithm Analysis:
1) Sentiment Analysis Evaluate Neg and Pos words:
2) Twitter Analytics Using R:
3) Sentiment Analysis Bernie Sanders:
4) Getting Started with Twitter Analysis:
Make a Twitter Bot with R
This is my stab at making a Twitter Bot with R following along with this tutorial from Automated Data Collection with…