Skip to content

Instantly share code, notes, and snippets.

@monogenea
Created October 7, 2019 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monogenea/7f9b5c77aced21dbc7253dd6ea1f33a8 to your computer and use it in GitHub Desktop.
Save monogenea/7f9b5c77aced21dbc7253dd6ea1f33a8 to your computer and use it in GitHub Desktop.
# Wed May 8 21:22:45 2019 ------------------------------
# Use status_id to identify and exclude duplicates
library(rtweet)
# List all files
allFiles <- paste0("tweets/", list.files("tweets/"))
# Write function to merge tweets
mergeTweets <- function(recipient, donor){
idx <- !donor$status_id %in% recipient$status_id
return(do_call_rbind(list(recipient, donor[idx, ])))
}
for(i in allFiles){
if(i == allFiles[1]){
allTweets <- read_twitter_csv(file = i,
unflatten = T)
}else{
tmp <- read_twitter_csv(file = i,
unflatten = T)
allTweets <- mergeTweets(allTweets, tmp)
}
}
# Write CSV
write_as_csv(allTweets, file_name = "gotTwitter.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment