Skip to content

Instantly share code, notes, and snippets.

@yonicd
Created April 12, 2019 13:24
Show Gist options
  • Save yonicd/bdb3408eeab1bbe84aa7cb31dda30296 to your computer and use it in GitHub Desktop.
Save yonicd/bdb3408eeab1bbe84aa7cb31dda30296 to your computer and use it in GitHub Desktop.
code to retrieve @AnandWrites adhoc survey replies
library(magrittr)
library(rtweet)
root_status <- '1116361675618361345'
x1 <- rtweet::lookup_tweets(root_status)
# The question
cat(x1$text)
#> Who do you:
#>
#> (A) most want to win the Democratic primary?
#>
#> (B) least want to win the Democratic primary?
#>
#> (C) anticipate will win the Democratic primary?
query <- sprintf('to:%s since:%s',x1$screen_name,as.Date(x1$created_at))
query_result <- rtweet::search_tweets(query,n = 2000)
#filter out replies to root status
status_replies <- query_result[query_result$reply_to_status_id==root_status,]
#remove any NA reply_to_status_id
status_replies <- status_replies[!is.na(status_replies$reply_to_status_id),]
# number of answers
nrow(status_replies)
#> [1] 1222
# non formated answers to tabulate (first 5)
cat(paste(head(status_replies$text),collapse = '\n\n'))
#> @AnandWrites A) Andrew Yang
#> B) Elizabeth Warren
#> C) Joe Biden
#>
#> @AnandWrites (A) Warren / Sanders
#> (B) Biden
#> (C) Biden / Harris
#>
#> @AnandWrites Buttigieg
#> Biden
#> Harris
#>
#> @AnandWrites A) Any living thing
#> B) The media consensus
#> C) Don Jr
#>
#> @AnandWrites @berniemyman2020 A) Bernie
#> B) Biden
#> C) probably Kamala, which isn't great but is miles better than Biden
#>
#> @AnandWrites A) Warren
#> B) Biden
#> C) Biden or Sanders (I’d be happy with Sanders)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment