Skip to content

Instantly share code, notes, and snippets.

@tts
Created July 9, 2012 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tts/3076126 to your computer and use it in GitHub Desktop.
Save tts/3076126 to your computer and use it in GitHub Desktop.
Statistics of Twitter clients by a list of users
library(RCurl)
library(RJSONIO)
library(XML)
# Function for getting a selection (here 100) of Twitter sources, ie clients used by a given user
get_clients <- function(user) {
u <- paste("https://api.twitter.com/1/statuses/user_timeline.json?",
"&screen_name=", user, "&count=100", sep = "")
json <- getURL(u)
dat <- fromJSON(json)
sapply(dat, function(d) d$source)
}
# Initialize a char vector for storing all source info
cl.all <- character(0)
# Get client info by user
# ppl = list of Twitter screen names
for (i in 1:length(ppl))
{
cl <- get_clients(ppl[i])
cl.all <- c(cl, cl.all)
}
# Get the name of the client
# Code from cran.r-project.org/web/packages/twitteR/vignettes/twitteR.pdf
clients <- gsub("</a>", "", cl.all)
clients <- strsplit(clients, ">")
clients <- sapply(clients, function(x) ifelse(length(x) > 1, x[2], x[1]))
# Plot a dotchart
op <- par(xaxs="i")
dotchart(table(clients), cex= .4, main="Twitter client stats", xlim=c(0, 5000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment