I have this code in R:
output = list()
for (i in 1:999)
{tryCatch({
{
link_i<- paste0(www.some_website, i+1, /some_extension/, i, .com)
material_i <- fromJSON(link_i)
output[[i]] <- material_i
}
}, error = function(e){})
}
Due to the nature of the code I am running, I have noticed that sometimes this loop gets "stuck" on a specific iteration. For instance, this loop might get stuck on the 45th iteration and take a very long time.
I am looking for some mechanism to tell the computer that "if more than x seconds is spent on a certain iteration, skip to the next iteration".
I found this function over here that might be useful : https://www.rdocumentation.org/packages/R.utils/versions/2.11.0/topics/withTimeout - but I am not sure if this is the correct function to use for such a task.
Can someone please recommend something and please show me how to use it?
Thank you!