Send tweets from R: A very short walkthrough
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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.
So, here I will run you through all the steps you have to take using
– Twitter’s API and
– the twitteR package written by Jeff Gentry
The setup to send myself tweets is the following: I have my main twitter account and an additional account 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.
Let’s get started.
Step 1: Create an additional twitter account and log in with this one.
Step 2: Go to apps.twitter.com (Application Management) and create a new app. After completing the process your Application Management main screen should look something like this.
setup_twitter_oauth(consumer_key = “
access_token = “
consumer_secret = “
access_secret = “
gauss <- rnorm(n = 10000)
jpeg(“temp.jpg”)
plot(density(gauss))
dev.off()
t2 <- difftime(Sys.time(), t1, units = "secs") tw <- updateStatus(paste("Finished in", round(t2, 2), "seconds"), mediaPath = "temp.jpg")
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.