0

From a txt document I will have a list of companies, say Telstra, Optus and Samsung.

After importing this list into R, I need a loop that will do the equivalent of the code below. The list could be any number of companies so my main issue here is that it needs to be automated.

df1 <- search_tweets2("Telstra", retryonratelimit = TRUE,include_rts=FALSE)
df2 <- search_tweets2("Optus", retryonratelimit = TRUE,include_rts=FALSE)
df3 <- search_tweets2("Samsung", retryonratelimit = TRUE,include_rts=FALSE)

Thanks.

jay
  • 47
  • 3

1 Answers1

0

We may use lapply or purrr's map functions to loop through each company name. If there are lot of companies to search for use Sys.sleep to avoid hitting the limit.

df <- data.frame(companies = c("Telstra", "Optus", "Samsung"))

result <- purrr::map_df(df$companies, ~{
  search_tweets2(.x, retryonratelimit = TRUE,include_rts=FALSE)
  #Sys.sleep(5)
}, .id = 'id')
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213