[R] Stopping all code execution when ANY error occurs (OR error handling without try/tryCatch)

Rui Barradas ruipbarradas at sapo.pt
Sun Aug 12 17:39:10 CEST 2012


Hello,

Something like this?


x <- 1:5  # vector with more than one element
# warning, execution continues
if(x == 2) print(2) else print("No!")

ow <- options(warn = 2) # all warnings are now errors
# error, else clause not executed
if(x == 2) print(2) else print("No!")
options(ow)  # reset default warn level


(Another way is the well known print function plus wait for execution to 
stop.)

Hope this helps,

Rui Barradas

Em 12-08-2012 02:56, enocko escreveu:
> Hi, thanks for the ideas, folks.
>
> I'm on Windows 7, R 2.15.0 x64, RStudio 0.97.71.
>
> I do appreciate your time... I would like to say my goal of dealing with
> errors without R's error trapping tools is not nonsensical given that those
> tools are cumbersome and not well-suited to the development phase of coding
> where one informally runs various snippets all the time.
>
> The suggestion of looking at IDE's is a good one because it would not be
> hard for an IDE to just wait and see if any line of code gives an error, and
> halt execution if so (a global option could enable this). RStudio doesn't
> have this--does anyone know of something that does? I can post a suggestion
> to RStudio.
>
> Thanks,
>
> Phil
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Stopping-all-code-execution-when-ANY-error-occurs-OR-error-handling-without-try-tryCatch-tp4640023p4640073.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list