所以对我来说,当我
search_tweets
对于没有tweets的句柄(即“@bannerchildrens”),我返回一个长度为0的空data.frame。通过添加if语句,可以排除所有没有tweets的句柄。下面的代码返回我的全局环境中的三个数据帧(“@uchkd”、“@aidhc”、“@baptistonline”),没有错误。
handles=data.frame(`Twitter Handle`=c("@_CHKD","@AIDHC","@BannerChildrens","@BaptistOnline"), stringsAsFactors = FALSE)
for(handle in handles$Twitter.Handle) {
result <- search_tweets(handle, n = 3500 , include_rts = FALSE,retryonratelimit = TRUE)
if(length(result) != 0){
result$`Twitter Handle` <- handle
result$Source <- "Search"
df_name <- paste0(tolower(substring(handle, 2)),"_search")
if(exists(df_name)) {
assign(df_name, unique(rbind(get(df_name), result)))
} else {
assign(df_name, result)
}
}
}