Learn R Programming

⚠️There's a newer version (0.32.7) of this package.Take me there.

vosonSML

vosonSML is an R package that provides a suite of tools for collecting and constructing networks from social media data. It provides easy-to-use functions for collecting data across popular platforms and generating different types of networks for analysis.

vosonSML is the SocialMediaLab package, renamed. We decided that SocialMediaLab was a bit too generic and also we wanted to indicate the connection to the Virtual Observatory for the Study of Online Networks Lab, where this package was conceived and created.

vosonSML was created by Timothy Graham and Robert Ackland with major contributions by Chung-hong Chan. The current lead developer and maintainer is Bryan Gertzel.

Supported Social Media

vosonSML currently features the collection of data and generation of networks from twitter, youtube and reddit.

Unfortunately we are no longer able to maintain facebook and instagram collection, however code for these platforms is still available in releases prior to version 0.25.0.

Installation

Install vosonSML from CRAN:

install.packages("vosonSML")

Install the latest Github release:

install.packages("https://github.com/vosonlab/vosonSML/releases/download/v0.27.2/vosonSML-0.27.2.tar.gz", 
  repo = NULL, type = "source")

or install the latest dev version:

# library(devtools)
devtools::install_github("vosonlab/vosonSML")

Note about previous releases: The vosonSML package was previously in a subdirectory, so if you wish to install versions prior to 0.26 please remember to include the subdir parameter.

# library(devtools)
devtools::install_github("vosonlab/vosonSML@v0.25.0", subdir = "vosonSML")

Getting started

The following usage examples will provide a great introduction to using vosonSML. There are also several "how to" guides, including an "Absolute Beginners Guide to vosonSML" tutorial aimed at people with little or no programming experience on the vosonSML page of the VOSON website.

Usage

The process of authentication, data collection and creating social network in vosonSML is expressed with the three verb functions: Authenticate, Collect and Create. The following are some examples:

Twitter Examples

library(magrittr)
library(vosonSML)

# Authenticate with twitter, Collect 100 tweets for the '#auspol' hashtag and Create an actor and 
# semantic network
myKeys <- list(appName = "My App", apiKey = "xxxxxxxxxxxx", apiSecret = "xxxxxxxxxxxx", 
               accessToken = "xxxxxxxxxxxx", accessTokenSecret = "xxxxxxxxxxxx")
  
twitterAuth <- Authenticate("twitter", appName = myKeys$appName, apiKey = myKeys$apiKey, 
                            apiSecret = myKeys$apiSecret, accessToken = myKeys$accessToken,
                            accessTokenSecret = myKeys$accessTokenSecret)

# twitter authentication creates an access token as part of the auth object
# this can and should be re-used by saving it and then loading it for future sessions
# Save the auth object after Authenticate 
saveRDS(twitterAuth, file = "~/.twitter_auth")

# Load a previously saved auth object for use in Collect
twitterAuth <- readRDS("~/.twitter_auth")

# Collect tweets
twitterData <- twitterAuth %>%
               Collect(searchTerm = "#auspol", searchType = "recent", numTweets = 100, 
                       includeRetweets = FALSE, retryOnRateLimit = TRUE, writeToFile = TRUE, 
                       verbose = TRUE)

# Create a network
actorNetwork <- twitterData %>% Create("actor", writeToFile = TRUE, verbose = TRUE)

actorGraph <- actorNetwork$graph # igraph network graph

# Optional step to add additional twitter user info to actor network graph as node attributes 
actorNetWithUserAttr <- AddTwitterUserData(twitterData, actorNetwork,
                                           lookupUsers = TRUE, 
                                           twitterAuth = twitterAuth, writeToFile = TRUE)

actorGraphWithUserAttr <- actorNetWithUserAttr$graph # igraph network graph

semanticNetwork <- twitterData %>% Create("semantic", writeToFile = TRUE)

Youtube Examples

library(magrittr)
library(vosonSML)

# Authenticate with youtube, Collect comment data from videos and then Create an actor network
myYoutubeAPIKey <- "xxxxxxxxxxxxxx"

myYoutubeVideoIds <- GetYoutubeVideoIDs(c("https://www.youtube.com/watch?v=xxxxxxxx",
                                          "https://youtu.be/xxxxxxxx"))
                                 
actorNetwork <- Authenticate("youtube", apiKey = myYoutubeAPIKey) %>%
                Collect(videoIDs = myYoutubeVideoIds) %>%
                Create("actor", writeToFile = TRUE)

Reddit Examples

library(magrittr)
library(vosonSML)

# Collect reddit comment threads and Create an actor network with comment text as edge attribute
myThreadUrls <- c("https://www.reddit.com/r/xxxxxx/comments/xxxxxx/x_xxxx_xxxxxxxxx/")

actorNetwork <- Authenticate("reddit") %>%
                Collect(threadUrls = myThreadUrls, waitTime = 5) %>%
                Create("actor", includeTextData = TRUE, writeToFile = TRUE)

Save and Load Authentication Objects

# Save the object after Authenticate 
saveRDS(my_youtube_auth, file = "~/.youtube_auth")

# Load a previously saved authentication object for use in Collect
my_youtube_auth <- readRDS("~/.youtube_auth")

For more detailed information and examples, please refer to the function Reference page.

Special thanks

This package would not be possible without key packages by other authors in the R community, particularly: igraph, rtweet, RedditExtractoR, data.table, tm, magrittr, httr and dplyr.

Copy Link

Version

Install

install.packages('vosonSML')

Monthly Downloads

322

Version

0.27.2

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Bryan Gertzel

Last Published

July 18th, 2019

Functions in vosonSML (0.27.2)

Create.bimodal.twitter

Create twitter bimodal network
Authenticate.youtube

Youtube API authentication
Collect.twitter

Collect tweet data from twitter search
Collect.youtube

Collect comments data for youtube videos
Create.semantic.twitter

Create twitter semantic network
Create

Create networks from social media data
vosonSML::AddTwitterUserData

Enhances twitter actor network graph by adding user attributes to nodes
Authenticate.reddit

Reddit API authentication
Authenticate

Create a credential object to access social media APIs
Create.actor.twitter

Create twitter actor network
vosonSML-package

Collection and network analysis of social media data
vosonSML::ImportData

Import collected data previously saved to file
Create.actor.reddit

Create reddit actor network
Create.actor.youtube

Create youtube actor network
vosonSML::GetYoutubeVideoIDs

Extract the ids from a list of youtube video URLs
Collect

Collect data from social media for generating networks
Authenticate.twitter

Twitter API authentication
Collect.reddit

Collect comments data from reddit threads