How to track Twitter unfollowers in R

July 18, 2012

(This article was first published on Quantitative thoughts » EN, and kindly contributed to R-bloggers)

I have Twitter account and it is relatively easy to see new followers or subscribers. However, I was looking for ways to know who are the unfollowers. I have noticed, that some (un)subscriptions happen in bulks, which made me thinking that either I tweeted some bullshit and upset bunch of people or spam bots work in sync. With that in mind I have created a simple R script, which produces Markdown and html reports about unfollowers. You can find an example of such report below.

The advantage of this script is that it does not require you to sign or share your data. You just have to install twitter package and you ready to go. Nevertheless, if you want to create Markdown report, you need to install markdown and knitr packages.

The source code and build scripts can be found here.

?View Code SPLUS
```{r echo=FALSE,message=FALSE}
  ## when file doesn't exist - take users list and add some artificial user
users=lookupUsers(old_list[which(!(old_list %in% as.character(tmp)))])
  ## stop() doesn't work under knitr
  cat('no one left you')  
```{r comment=NA,echo=FALSE,message=FALSE,results='asis'}
for(i in 1:length(users))
cat(paste("**",users[[i]]$name," @",users[[i]]$screenName,"**", "\n===\n",sep=""))
cat(paste("  \n**Created:** ",users[[i]]$created,
          "  \n**Spam rate:** ",round(users[[i]]$followersCount/users[[i]]$friendsCount,digits=2),
          "  \n**Activity:** " , users[[i]]$statusesCount,
          "  \n**Location:** ", users[[i]]$location,"  \n",users[[i]]$description,"  \n",
          "**Last status:** ",(users[[i]]$lastStatus$text),"\n\n",sep=""))
```{r comment=NA,echo=FALSE,message=FALSE,results='asis'}

Dzidas @dzidorius

Created: 2010-02-18 13:09:29
Spam rate: 0.98
Activity: 315
Location: Luxembourg
Java, C++ and R developer & data junkie
Last status: It is rainy summer in #Luxembourg but there is a party!

To leave a comment for the author, please follow the link and comment on their blog: Quantitative thoughts » EN. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


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)