Skip to content

Instantly share code, notes, and snippets.

@jeffreyhorner
Created December 17, 2010 23:04
Show Gist options
  • Save jeffreyhorner/745871 to your computer and use it in GitHub Desktop.
Save jeffreyhorner/745871 to your computer and use it in GitHub Desktop.
Maps your follower names to R variables located in an environment on your search path. Each variable contains a list of influence scores for that follower.
library(twitteR)
library(infochimps)
library(datamap)
infochimps('YOUR_API_KEY')
# Creates a new mapper, similar to an OO class
newMapper(type='twitchimps:influence',
# Init is called once during newMap(). Note that
# since it's called only once, your friend list, wether you
# add or drop some later, will stay constant.
init = function(map,user){
install(
unlist(lapply(userFriends(user), function(n) screenName(n))),
map
)
TRUE
},
# Get is called real-time on each access to the variable
get = function(user) influence(user)
)
# Install the map at position 2 on the search path
mapAttach(newMap('twitchimps:influence','YOUR_TWITTER_NAME_HERE'),pos=2)
# List all your friends
ls(2)
# Their names are now variables. Enter one at the R prompt and see that
# it contains their infochimps influence.
# Create a data frame. You may want to use head(ls(2)) instead of ls(2)
# if you have quite a few followers.
x <- data.frame()
lapply(
ls(2),
function(i){
y <- get(i)
if(!is.na(y))
x <<- rbind(x,as.data.frame(y))
}
)
summary(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment