I'm currently working on a project where I'm trying complete a task in a for loop. There are a lot of areas where something can go wrong (it involves creating a pdf report via rmarkdown), but in this case I don't care if something goes wrong, I just want the for loop to keep going.
In the toy example below I would like to be able to print off the numbers 2 through 16, while skipping over the letter 'a'.
something<-function(x){
print(x + 1)
}
for(i in c(1:10,'a',11:15))
{
res <- try(something(i))
if(inherits(res, "try-error"))
{
#error handling code, maybe just skip this iteration using
next
}
#rest of iteration for case of no error
}
This is loosely based on the example provided in the answer below.
R Script - How to Continue Code Execution on Error.
I've tried adapting several other "how do I continue a for loop in R" to no success.
I'm not a full time programmer, so I'm convinced I'm missing something very simple, but any help would be appreciated.