Skip to content

Instantly share code, notes, and snippets.

@mermelstein
Last active January 5, 2024 20:54
Show Gist options
  • Save mermelstein/5e843cb75aca221249732c6a79997dad to your computer and use it in GitHub Desktop.
Save mermelstein/5e843cb75aca221249732c6a79997dad to your computer and use it in GitHub Desktop.
twitter data to df
library(jsonlite)
library(brio)
# where is the archive directory
dir_path <- "~/Downloads/twitter-archive/data"
# file in /data with the tweets
filename <- "tweets.js"
# get full file path
js_file_path <- file.path(dir_path, filename)
f <- brio::read_file(js_file_path)
data <- jsonlite::fromJSON(substr(f, 27, nchar(f)), flatten = TRUE)
data <- as.data.frame(data)
# check out tweets
head(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment