Is there anyway to stop my loop from being interrupted by the rate limit? I would like my code to wait to execute until the time limit has passed if possible.
A side
What I ended up doing was create a while loop that checked the number of records I had left in my Users vector, ran my for loop, and then put the system to sleep for 15 mins. This approach is good, but there are some things to account for. I have the while loop breaking at 200 just in case there were users that didn't have any data to save into a csv. This turned out to be a good move because if you notice the for loop starts iterating at 80. As you start moving across your vector of users the good users are removed iteratively. This leaves only the users that cause errors. An improvement for someone up to the task would be to handle this programatically.
Users <- usrs$user_id
goodUsers <- substring(list.files(),1,nchar(list.files())-11)
Users <- setdiff(Users,goodUsers)
while(length(Users)>200){
for(i in 80:length(Users)){
a<-tryCatch({get_timeline(Users[i],usr=FALSE)},
error=function(e){message(e)}
)
tryCatch({save_as_csv(a,Users[i])
goodUsers <- append(goodUsers,Users[i])},
error=function(e){message(e)}
)
}
Users <- setdiff(Users,goodUsers)
Sys.sleep(900)
}
length(Users)
length(goodUsers)