Skip to content

Instantly share code, notes, and snippets.

@tts tts/gist:3076126
Created Jul 9, 2012

What would you like to do?
Statistics of Twitter clients by a list of users
# Function for getting a selection (here 100) of Twitter sources, ie clients used by a given user
get_clients <- function(user) {
u <- paste("",
"&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
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
You can’t perform that action at this time.