knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%",
  message = FALSE
)

tidytags

Importing and Analyzing 'Twitter' Data Collected with 'Twitter Archiving Google Sheets'
Release Usage Development Checks
CRAN Version Licence Repo Status CRAN checks
Minimal R Version Monthly Downloads Lifecycle R-CMD-Check
rOpenSci Peer Review Total Downloads Last Commit Code Coverage

Overview

The purpose of tidytags is to make the collection of Twitter data more accessible and robust. tidytags retrieves tweet data collected by a Twitter Archiving Google Sheet (TAGS), gets additional metadata from Twitter via the rtweet R package, and provides additional functions to facilitate a systematic yet flexible analyses of data from Twitter. TAGS is based on Google spreadsheets. A TAGS tracker continuously collects tweets from Twitter, based on predefined search criteria and collection frequency.

In short, tidytags first uses TAGS to easily collect tweet ID numbers and then uses the R package rtweet to re-query the Twitter API to collect additional metadata. tidytags also introduces functions developed to facilitate systematic yet flexible analyses of data from Twitter.

Two vignettes illustrate the setup and use of the package:


Installation

To get the current released version of tidytags from CRAN:

install.packages("tidytags")

Or you can install the development version of tidytags from GitHub:

install.packages("tidytags", repos = "https://ropensci.r-universe.dev")

Once installed, use the library() function load tidytags:

library(tidytags)

Setup

For help with initial tidytags setup, see the Getting started with tidytags vignette (vignette("setup", package = "tidytags")). Specifically, this guide offers help for two key tasks:

  1. Making sure your TAGS tracker can be accessed
  2. Getting and storing Twitter API tokens

Usage

To test the tidytags package, you can use an openly shared TAGS tracker that has been collecting tweets associated with the AECT 2019 since September 30, 2019. This is the same TAGS tracker used in the Using tidytags with a conference hashtag vignette (vignette("tidytags-with-conf-hashtags", package = "tidytags")).


Core Functions

read_tags()

At its most basic level, tidytags allows you to import data from a Twitter Archiving Google Sheet (TAGS) into R. This is done with the googlesheets4 R package. One requirement for using the googlesheets4 package is that your TAGS tracker has been "published to the web." See the Getting started with tidytags vignette (vignette("setup", package = "tidytags")), Key Task #1, if you need help with this.

Once a TAGS tracker has been published to the web, you can import the TAGS archive into R using read_tags().

example_tags <- "18clYlQeJOc6W5QRuSlJ6_v3snqKJImFhU42bRkM_OX8"
tags_data <- read_tags(example_tags)
head(tags_data)

pull_tweet_data()

With a TAGS archive imported into R, tidytags allows you to gather quite a bit more information related to the collected tweets with the pull_tweet_data() function. This function uses the rtweet package (via rtweet::lookup_tweets()) to query the Twitter API.

This process requires Twitter API keys associated with an approved Twitter developer account. See the Getting started with tidytags vignette (vignette("setup", package = "tidytags")), Key Task #2, if you need help with this.

app <- rtweet::rtweet_app(bearer_token = Sys.getenv("TWITTER_BEARER_TOKEN"))
rtweet::auth_as(app)

expanded_metadata <- pull_tweet_data(tags_data, n = 10)
expanded_metadata

Workflow

The following diagram represents how the functions included in the tidytags package may work together. These are presented in the figure below.

tidytags workflow


Learning More About tidytags

For a walkthrough of numerous additional tidytags functions, see the Using tidytags with a conference hashtag vignette (vignette("tidytags-with-conf-hashtags", package = "tidytags")).


Getting Help



Considerations Related to Ethics, Data Privacy, and Human Subjects Research



Contributing

If you encounter an obvious bug for which there is not already an active issue, please create a new issue with all code used (preferably a reproducible example) on GitHub.

If you would like to become a more involved contributor, please read the Contributing Guide.

Contributor Code of Conduct

Please note that this package is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.


How to Cite This Package in Publications

You can cite this package like this: "we collected, processed, and analyzed Twitter data using the tidytags R package (Staudt Willet & Rosenberg, 2022)". Here is the full bibliographic reference to include in your reference list:

Staudt Willet, K. B., & Rosenberg, J. M. (2022). tidytags: Importing and analyzing Twitter data collected with Twitter Archiving Google Sheets. https://github.com/ropensci/tidytags


License license

The tidytags package is licensed under the MIT License. For background on why we chose this license, read this chapter on R package licensing.



bretsw/rtags documentation built on Feb. 4, 2024, 6:20 a.m.