Stopping all code execution when ANY error occurs (OR error handling without try/tryCatch)
Hi Phil, I really have to concur with Uwe Ligges here. You probably want to wrap everything in a function. Because usually this is where long lines of code will end up. The browser() function makes this option really useful, as you can step inside the temporary environment and work from there as if you are in the global environment with the added benefits that all your variables will be gone when you exit the execution, so you start with a new blank environment the next time you call the function. And if you put the browser call to the botton of your functions, any error before will halt execution. The downsites are, that you need to execute the function code each time you make changes to the function prior to rerunning it. But IDEs will help on this by sourcing a function qith simple keystrokes (e.g., C-c C-f in ESS-Emacs). However, if there is a syntax error, the original problem remains. An alternative to browser() is to use options(error = recover) when working with functions. It is also extremely helpful, as it brings you to the point of the function where the error occurs to work from there. Give it a try. BTW, I got the info with browser(error = recover) from the Chambers book: Sofwtare for Data analysis. It is worth a buy. Cheers, Henrik enocko schrieb:
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.
Dipl. Psych. Henrik Singmann PhD Student Albert-Ludwigs-Universit?t Freiburg, Germany http://www.psychologie.uni-freiburg.de/Members/singmann