twinfoR: A package for mining Twitter.

This package provides methods for collecting and analyzing data from the Twitter REST APIs.

What this package does

The goal of this package is to make it very easy to send user authenticated queries to the Twitter REST APIs, and collect, store, and analyze the response data.

Installation and Getting Started

Install from the compiled .zip file provided, as shown below from the R Console. After installing, check out the documentation.

> install.packages("twinfoR.zip",repos=NULL,type="binary")}
> ?twinfoR::twinfoR

If you do not have a copy of this package and would like one, send a request to cemarks at alum.mit.edu.

Authentication

The authorize_app and authorize_IT provide methods to obtain access tokens needed for most API methods. These methods require the user to log on to Twitter and authorize a Twitter Application on the user’s account. You must have a Twitter account to authenticate.
Without a Twitter account, this package will be of very limited use. When calling either of the authentication functions, use care not to hit following the call to the function until you have authorized the App in your browser, retrieved the PIN, and entered the PIN into the R console. This mistake is easy to make if you are copying and pasting the authentication function into the console.

All methods in this package that send requests to the Twitter REST APIs, with the single exception of twitter_request, look for user authentication credentials in a variable named auth.vector if credentials are not supplied to the function.

Twitter Requsts

The workhorse function for this package is twitter_request. It can be used to send a user authenticated request to any of the REST API endpoints. See twitter_request documentation for details. All functions in this package that send requests to the Twitter REST APIs call this function.

Basic API Methods

This package offers several functions that access common Twitter REST API endpoints and return the response. These functions are:

Recursive API Methods

Often it is useful to call the methods listed in the preceding section recursively, in order to continue to collect relevant data from the Twitter REST APIs. Twitter imposes rate limits on all of these API end points. The following functions recursively query the end points, but include a delay for each query in order to build a large data set without exceeding the rate limits. The recursive nature of these functions varies. Some functions are designed to iterate through more inputs than a single query can handle, e.g., status_lookup_recursive; others page through more results than can be returned by a single query, e.g., search_tweets_recursive. The recursive API request functions are

These recursive functions can return the results to the user, or, if a twitter_database connection is supplied, they will insert the results directly into the database. This specific database structure is provided in the next section.

Data

This package offers a useful SQLite data structure that can be initialized or re-established useing the twitter_database function.
Understanding this data structure and familiarity with SQLite syntax will enable a user to carry out a wide array of analyses that are tailored for specific scenarios using this package. Of particular note, the query_users and query_text tables enable a user to specify and categorize query criteria that can be executed and analyzed over a time horizon. The following functions act on a twitter_database connection, and interact with the query_text and query_users tables, enabling a wide range of collection and analysis capabilities.

Additionally, the following functions enable direct updates to a twitter_database, and are called by some of the functions listed above.

Analysis

While many analyses are situation dependent, this package provides several useful, basic analysis and plotting functions that have applicability in many use cases. These functions include the following:

The following functions produce plots of different aspects of the Twitter data.

Vignettes

The vignettes for this package demonstrate many of features described above. They are: