Twitter from R… Sure, why not!

[This article was first published on Cerebral Mastication » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.


So I have started following the #RStats tag in twitter. Prior to a week ago I had never Twitterbated so I thought I would give it a go since I am not one to shy away from new technology… much. I think of Twitter like a call in radio show where I get to cut off callers when they annoy me.

Well one of the interesting things I ran across was this tweet that pointed to this page about posting tweets from R.  The code example was missing a couple of things, so here’s the cleaned up version:

install.packages("RCurl")
library("RCurl")
opts = curlOptions(header = FALSE, userpwd = "username:password", netrc = FALSE)

update <- function(status){
  method <- "http://twitter.com/statuses/update.xml?status="
  encoded_status <- URLencode(status)
  request <- paste(method,encoded_status,sep = "")
  postForm(request,.opts = opts)
}
update("My first tweet from R! @CMastication is my daddy! #RStats")

This is a pretty good, and fairly self explanatory example of how to use RCurl to spew out some data. Don’t be a scriptard and try to run this without changing ‘username’ and ‘password.’ If you do, I’m coming to your house and going to beat you with your own keyboard until you admit that I am, indeed, your daddy.

Am I planning on Tweeting from R? You have to be kidding. That’s just silly. But I might need to use RCurl again. Although for long running scripts I may very well put code at the end of my scripts that sends out a Tweet when the code has finished running. Waaaay easier than setting up email and trying to ensure it runs from EC2 as well as my home machine, etc. The more I think about that, the more I am sure I’m a friggin genius. And of course, on every one of my script completion tweets I’m going to use the #RStats tag so everyone in twitterland will know that I am amazing. And a prick. All at the same time. I’m complex like that.

Oh yeah, I’m @CMastication on Twitter.

To leave a comment for the author, please follow the link and comment on their blog: Cerebral Mastication » R.

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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)