I have a dataframe of Twitter handles. When I loop over the handles using the search_tweets
function, the loop stops collecting tweets if one of the Twitter handles does not return any results.
I would like to construct the loop such that if no results are returned, it ignores the handle and moves to the next.
My handle dataframe looks like this:
handles=data.frame(`Twitter Handle`=c("@_CHKD","@AIDHC","@BannerChildrens","@BaptistOnline"))
And the loop looks like this:
# Loop through the twitter handles & store the results as individual dataframes
for(handle in twitter_handles) {
result <- search_tweets(handle, n = 3500 , include_rts = FALSE,retryonratelimit = TRUE)
result$`Twitter Handle` <- handle
result$Source <- "Search"
df_name <- paste(tolower(substring(handle, 2)),"_search")
if(exists(df_name)) {
assign(df_name, unique(rbind(get(df_name), result)))
} else {
assign(df_name, result)
}
}
When I run the loop, it throws the following error after it encounters a handle that returns nothing:
Error in fix.by(by.x, x) : 'by' must specify a uniquely valid column
I have tried to search online for a solution but I've not been successful. Any pointers would be very helpful.