<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/send-tweets-from-r-a-very-short-walkthrough/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://rcrastinate.blogspot.com/2018/05/send-tweets-from-r-very-short.html"> Rcrastinate</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>There are a few reasons why you might want to send tweets from R. You might want to write a Twitter bot or – as in my case – you want to send yourself a tweet when a very long computation finishes.</p>
<p>So, here I will run you through all the steps you have to take using<br>– <a rel="nofollow" href="https://developer.twitter.com/" target="_blank">Twitter’s API</a> and<br>– the <a rel="nofollow" href="https://cran.r-project.org/web/packages/twitteR/README.html" target="_blank">twitteR package</a> written by <a rel="nofollow" href="https://github.com/geoffjentry" target="_blank">Jeff Gentry</a></p>
<p>The setup to send myself tweets is the following: I have my <a rel="nofollow" href="https://twitter.com/sascha_wolfer" target="_blank">main twitter account</a> and an <a rel="nofollow" href="https://twitter.com/swolfR" target="_blank">additional account</a> I am only using to tweet from R. I am following the additional account with my main account. On my phone’s Twitter app, my main account is logged in and notifications are activated only for the additional account. So, whenever I tweet something with the additional account, the new tweet pops up on my phone.</p>
<p>Let’s get started.</p>
<p><b>Step 1</b>: Create an additional twitter account and log in with this one.<br><b>Step 2</b>: Go to <a rel="nofollow" href="http://apps.twitter.com/" target="_blank">apps.twitter.com</a> (Application Management) and create a new app. After completing the process your Application Management main screen should look something like this.</p>
<div><a rel="nofollow" href="https://i1.wp.com/2.bp.blogspot.com/-MFr6If-iG2k/Wu7TfWtFLkI/AAAAAAAADQ4/mHSJ3saGlbQQupQp3wHJwlNgBIAbVtnfACLcBGAs/s1600/app_screen.png?ssl=1" target="_blank"><img border="0" src="https://i1.wp.com/2.bp.blogspot.com/-MFr6If-iG2k/Wu7TfWtFLkI/AAAAAAAADQ4/mHSJ3saGlbQQupQp3wHJwlNgBIAbVtnfACLcBGAs/s400/app_screen.png?resize=450%2C550&ssl=1" data-original-width="450" width="450" data-original-height="550" data-recalc-dims="1"> </a></div>
<div><b>Step 3</b>: Click on the name of your app and then select “<span><span>manage keys and access tokens”. This should look like this (without the red boxes, of course).</span></span></div>
<div><a rel="nofollow" href="https://i1.wp.com/3.bp.blogspot.com/-DGQmOXANvTY/Wu7UVxsBsXI/AAAAAAAADRA/b24pw5HraB8Iq8d84_g-cIUG_RN8w-L-ACLcBGAs/s1600/access.png?ssl=1" target="_blank"><img border="0" src="https://i0.wp.com/3.bp.blogspot.com/-DGQmOXANvTY/Wu7UVxsBsXI/AAAAAAAADRA/b24pw5HraB8Iq8d84_g-cIUG_RN8w-L-ACLcBGAs/s400/access.png?resize=450%2C1457&ssl=1" data-original-width="450" width="450" data-original-height="1457" data-recalc-dims="1"> </a></div>
<div><b>Step 4</b>: Copy your Consumer Key, Consumer Secret, Access Token and Access Token Secret. You will need them for authenticating from your R script.</div>
<div><b>Step 5</b>: Fire up R and install the twitteR package.</div>
<div>  </div>
<div><span><span>install.packages(“twitteR”) </span></span></div>
<div><span><span>library(twitteR)<br>setup_twitter_oauth(consumer_key = “</span></span></div>