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: withTimeout: Evaluate an R expression and interrupts it if it takes too long, but I am not sure if this is the correct function to use for such a task.
What can be recommended and how can I to use it?