[R] running a function repeatedly on error....

akshay kulkarni @k@h@y_e4 @end|ng |rom hotm@||@com
Wed Apr 19 18:57:18 CEST 2023

Dear members,
                          I have a function FUN1 that downloads some data from the internet. It so happens that the function doesn't work the first time, but on the second or third attempt it works. I want to run the function repeatedly for four times if it throws an error:

X <- tryCatch(FUN1, error = function(c) {FUN1})

This runs the function two times. But I want to run the function four times if throws an error, but on the fifth attempt if it throws an error, abort. I know I can include the tryCatch call inside FUN1 and call it, but any short and elegant code to that effect?

Thanking you,
Yours sincerely

	[[alternative HTML version deleted]]

More information about the R-help mailing list