mundos
mundos

Reputation: 459

for loop with function that also sleeps after nrows [R]

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?

Upvotes: 0

Views: 95

Answers (1)

Shinobi_Atobe
Shinobi_Atobe

Reputation: 1983

We can use Sys.sleep():

i <- 1

while (i < n_accounts) {

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

}

Upvotes: 1

Related Questions