Re: [R] Error trapping in R

2019-02-28 Thread Bernard McGarvey
Thanks - the try() approach is exactly what I need. Lion Bernard McGarvey Director, Fort Myers Beach Lions Foundation, Inc. Retired (Lilly Engineering Fellow). > On February 27, 2019 at 4:39 PM Robert Knight wrote: > > Some use try blocks, like found in other languages. Put the code

Re: [R] Error trapping in R

2019-02-28 Thread Robert Knight
Some use try blocks, like found in other languages. Put the code you want to try inside the block. https://www.robertknight.io/blog/try-blocks-in-r-for-error-handling/ contains a quick example. The example doesn’t raise exceptions or anything, it just contains it for you so the script keeps g

Re: [R] Error trapping in R

2019-02-27 Thread Bernard Comcast
Thanks Bernard Sent from my iPhone so please excuse the spelling!" > On Feb 27, 2019, at 4:05 PM, Duncan Murdoch wrote: > >> On 27/02/2019 3:55 p.m., Bernard Comcast wrote: >> What is the recommended way to trap errors in R? My main need is to be able >> to trap an error and then skip a sectio

Re: [R] Error trapping in R

2019-02-27 Thread Rui Barradas
Hello, You can trap errors with ?try or ?tryCatch. Example: result <- vector(mode = "list", length = 5) for(i in 1:5){ result[[i]] <- tryCatch(if(i == 3) stop("This is an error") else 2*i + 1, error = function(e) e) } result for(i in seq_along(result)) { err <- inherits(result[

Re: [R] Error trapping in R

2019-02-27 Thread Duncan Murdoch
On 27/02/2019 3:55 p.m., Bernard Comcast wrote: What is the recommended way to trap errors in R? My main need is to be able to trap an error and then skip a section of code if an error has occurred. In VB for Excel I used the “On Error goto .” construct to do this. The recommended way is