Use tryCatch skip to next value of loop upon error?

后端 未结 5 1357
滥情空心
滥情空心 2020-11-29 15:51

I\'ve read a few other SO questions about tryCatch and cuzzins, as well as the documentation:

  • Exception handling in R
  • catching an error a
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 16:10

    One thing I was missing, which breaking out of for loop when running a function inside a for loop in R makes clear, is this:

    • next doesn't work inside a function.
    • You need to send some signal or flag (e.g., Voldemort = TRUE) from inside your function (in my case tryCatch) to the outside.
    • (this is like modifying a global, public variable inside a local, private function)
    • Then outside the function, you check to see if the flag was waved (does Voldemort == TRUE). If so you call break or next outside the function.

提交回复
热议问题