TryCatch handling in TERR

137 Views Asked by At

I'm having an issue with error handling in Spotfire, so I wrote this simple data function to throw an error when a function is called to divide a number by a character.

To me this code looks like it should return a data frame where the 4th row in column r equals 713, and the other rows are the result of 20/n.

However, the resulting data frame returned has 713's in all rows.

Any idea what I'm missing?

Thanks

divTest <- function(x){
    20/x
}

n <- -5:5
n[4] <- " "
out <- data.frame(n = n)
out$r <- NA

for(i in 1:length(n)){

   r <- tryCatch({
      divTest(n[i])
   },error = function(cond) {
      713
   })
   out$r[i] <- r 
}
0

There are 0 best solutions below