Beginner intro to the R package rtweet for scraping the Twitter API for tweets
- January 26, 2022
- the RLadies meetup description
- the Twitter datasets have been removed on Jan 27, 2022.
The link to my rtweet guide is here which was the learnr
file documentation/
Here are some of the functions for getting started.
library(rtweet)
library(tidytext) # text analysis and cleaning
library(ggplot2) # plot your data
Give your search functions variables, avoid rate limit errors. Maximum amount of tweets is 18,000 in a single API request and returns tweets <= 9 days old.
searched_tweets = search_tweets(
"rstats OR RStats", # the #hashtag or phrase you want to search
n = 4000, # number of tweets to capture
type = "recent", # recent | mixed | popular
include_rts = FALSE, # no retweets
verbose = TRUE,
retryonratelimit = FALSE, # set to true if you want it to run again
lang = "en" # English language tweets
)
Saving your Tweets keeps you safe from rate limit errors.
save_as_csv(
searched_tweets, # the name of your Twitter dataframe
file_name = "new_twitter_df_name",
prepend_ids = TRUE,
na = " ",
fileEncoding = "UTF-8"
)
twitter_df = read_twitter_csv(file = "<path>", unflatten= FALSE)