Skip to content

Instantly share code, notes, and snippets.

@dill
Last active January 5, 2018 10:45
Show Gist options
  • Save dill/6aff2f54ad14384d2115 to your computer and use it in GitHub Desktop.
Save dill/6aff2f54ad14384d2115 to your computer and use it in GitHub Desktop.
Make a grid of twitter folks I've met IRL
# you need my horse library from here: https://github.com/dill/horse
library(horse)
library(magrittr)
library(knitr)
setup_twitter_oauth("you auth stuff",
"goes here",
"you can't use mine",
"it's mine")
aa <- getUser("millerdl")
followers <- aa$getFollowers()
friends <- aa$getFriends()
all_f <- c(followers, friends)
all_fn <- all_f %>%
lapply(function(x) x$screenName) %>%
unlist
all_f <- all_f[!duplicated(all_fn)]
all_fn <- all_fn[!duplicated(all_fn)]
## write out this and go through it manually?!
write.csv(all_fn, file="test.csv")
## yeah do that manually -- this bit sucks
## now sift
rr <- read.csv(file="test.csv", header=FALSE)
# make this into a list of links wrapping profile images
tab <- lapply(rr[,2], function(x){
paste0("<a href=\"http://twitter.com/", x,
"\"><img src=\"", getUser(x)$profileImageUrl, "\"></a>")
})
## now make that into a matrix, then a data.frame
tab <- unlist(tab)
tab <- c(tab, rep("", 10*16-length(tab)))
tab <- as.data.frame(matrix(tab,16,10, byrow=TRUE))
# now output via kable
kable(tab, format="html", escape=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment