Years ago I intensely worked on analysis of Twitter networks using F# and came to the conclusion that:

Meanwhile I suppose that distributed graph algorithms and cloud computing is more and more a commodity, meaning that it has become easier to deal with Twitter as the prototypical social network. R also has become the de facto tool to do statistical analysis and in a previous note I highlighted the cool features of iGraph for doing graph analysis using R. Here I’d like to highlight the TwitteR library for accessing Twitter and do various things that I thought were somewhat tedious in F# (or any other language in that category).

First, I’d advice to use the pacman library for everything loading/installing R libraries. It’s a great and easy to use utility. So, fetch the twitteR and RSQLite libs like so;

library(pacman)
p_install(twitteR)
## 
## The downloaded binary packages are in
##  /var/folders/cr/csqq08hd59d1857fw0h69cf00000gn/T//RtmpWwQXQS/downloaded_packages
## 
## twitteR installed
p_install(RSQLite)
## 
## The downloaded binary packages are in
##  /var/folders/cr/csqq08hd59d1857fw0h69cf00000gn/T//RtmpWwQXQS/downloaded_packages
## 
## RSQLite installed
library(twitteR)
library(RSQLite)
## Loading required package: DBI
library(jpeg)

The RSQLite library is also on its own quite a delight. It’s a no-fuss wrapper to SQLite databases and works well with the TwitteR package. Next, you need to fetch the API key and API secret from your Twitter developer page to authorize your access to the Twitter mine

setup_twitter_oauth("Your_API_Key","Your_API_Secret") 
## [1] "Using browser based authentication"

You will be guided in the usual way in a browser session and the best part is when TwitteR asks you whether you’d like to cache the credentials. It turns TwitteR in a Twitter client with integrated analysis. For example, take any account and you can access any property in a snap;

# get a user
user = getUser('theorbifold')
# get the picture
z <- tempfile()
download.file(user$profileImageUrl,z,mode="wb")
pic <- readJPEG(z, TRUE)
file.remove(z) # cleanup
## [1] TRUE
if (exists("rasterImage")) { # can plot only in R 2.11.0 and higher
  plot(1:2, type='n') 
  rasterImage(pic, 1.2, 1.27, 1.8, 1.73) 
}

or access the followers with a sample of the tweets without the retweets

# get the followers
user$getFollowersCount()
## [1] 468
tweets = searchTwitter('#rstats', n=50)
head(strip_retweets(tweets,strip_manual=TRUE,strip_mt=TRUE))
## [[1]]
## [1] "Rbloggers: Dockerizing a Shiny App http://t.co/Bn4rZ06n0u #rstats"
## 
## [[2]]
## [1] "earino: Though I have to admit, being able to drop into this is shockingly powerful. #AzureML #rstats http://t.co/pKbcgMeUkm"
## 
## [[3]]
## [1] "ramnath_vaidya: Hacking #swirl to get a cat to teach you #rstats  https://t.co/gWYb6Dwmvr via @rdpeng @jtleek @_inundata"
## 
## [[4]]
## [1] "Emaasit: Leaflet package in a #shiny app at @DataScienceLV #Rstats #dslv #DataScience http://t.co/IDCkS7bS8t"
## 
## [[5]]
## [1] "Rbloggers: Le Monde puzzle [#909] http://t.co/vHPgZfgc5q #rstats"
## 
## [[6]]
## [1] "sfrechette: \"Rstats\" on Tweeted Times #rstats http://t.co/X6haMFDKGP - top stories by @dirkvandenpoel, @earino, @NikoNeugebauer"

which can be turned in a data frame

df = twListToDF(tweets)

or stored in a database for later access

# to database

sql_lite_file = tempfile()
register_sqlite_backend(sql_lite_file)
store_tweets_db(tweets)
## [1] TRUE
# load them again
from_db=load_tweets_db()

Things can't get easier than this really. Certainly in comparison to what one would have to do outside R in order to get to the same point; linking libraries, setting up a database, downloading an appropriate Twitter library (often not maintained very well) and so on. There is much to enjoy in R really.