0

I am using rtweet to lookup_users for a very large number of accounts (>900,000). This function returns up to 90,000 users and then there is a rate limit, which only resets after 15 minutes. How do I build a for loop that iterates over the first 90,000 values in a vector (or dataframe) and then waits 15 minutes, then iterates over the next 90,000, etc., respecting the rate limit?

mundos
  • 459
  • 6
  • 14
  • 1
    perhaps `Sys.sleep(15 * 60 / 90000)` at the end of the loop? Effectively a 0.01 second pause at each iteration ensures you don't ever exceed the limit. – Benjamin Jul 02 '18 at 13:18

1 Answers1

1

We can use Sys.sleep():

i <- 1

while (i < n_accounts) {

do_something()
Sys.sleep(900)
i <- i + 90000

}
Shinobi_Atobe
  • 1,793
  • 1
  • 18
  • 35