3

I would like to use sys.sleep function when the request of an API I am using gives me an error back. Like this one:

Error in open.connection(con, "rb") : HTTP error 429.

Should I use trycatch?

data<- fromJSON("https://api.com")

Thanks !

1 Answer 1

3

You can use try catch

tryCatch(myfunc(), error=function(e) Sys.sleep(1))
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot ! It seems to work well, although it looks that it will just do Sys.sleep after 1 error, but after a 2nd error it won't do it again. So could I mix what you suggested with a while loop ? In order to say that "as long as there is an error, do Sys.sleep"
I think the following is what you are looking for. Take a look at the retry function that is posted , it will do to retry an operating a configurable number of times, with a configurable wait between attempts stackoverflow.com/questions/20770497/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.