Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR R

next element in a loop if error in r

# This solution still prints the error but doesn't stop the loop
for (i in 1:10) {
  tryCatch({
    print(i)
    if (i==7) stop("Urgh, the iphone is in the blender !")
  }, error=function(e){cat("ERROR :",conditionMessage(e), "
")})
}

[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
ERROR : Urgh, the iphone is in the blender ! 
[1] 8
[1] 9
[1] 10
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #element #loop #error
ADD COMMENT
Topic
Name
4+5 =