0

I write the next for loop-

df_total<-data.frame()
**for (i in unique(danadata$product))
{
  maindatatest <- danadata %>%  filter(product %in% i )
  print(i)

  df <-  synth.func(maindatatest)
  df_total<-rbind(df_total,df)
}**

Everything works fine, until I get the next error-

> Error in svd(c) : infinite or missing values in 'x'

I do not fully understand what is causing the problem because I run on the same problem i separately the function it works. Anyway, I want to skip the error and the loop will continue to work. I realized I should add something that looks like this -

for (i in 1:10) {

  skip_to_next <- FALSE

  # Note that print(b) fails since b doesn't exist

  tryCatch(print(b), error = function(e) { skip_to_next <- TRUE})

  if(skip_to_next) { next }     
}

I can't integrate the solution to the original loop error above, I'd love for help. In addition, I want to get a list of those i that caused the problem so I will deal with them separately.

Thanks!

  • 1
    Hi Rotem, you can assign the tryCatch result into a variable and later get the errors. Though it's a different question, but you can look here for a similar solution https://stackoverflow.com/questions/59273046/how-to-force-a-for-loop-or-lapply-to-run-with-error-message-in-r/59275629#59275629. It's a bit difficult to help you more than that as you didn't supply a sample data. – DJV Dec 25 '19 at 10:01
  • 1
    Please add a reproducible example along with expected output. Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Dec 25 '19 at 11:15

0 Answers0