How to *completely* stop a script after stop()?
----------------------------------------
Date: Sat, 15 Jan 2011 11:29:20 -0500 From: carl at witthoft.com To: r-help at r-project.org Subject: [R] How to *completely* stop a script after stop()? Somehow this reminds me of a famous FORTRAN code snippet: 10 STOP STOP STOP ! IN CASE STILL SKIDDING GOTO 10
you can laugh about it but I actually have had to write code like this in interactive applications ( I guess you could laugh at me too LOL) and sometimes you need it but sometimes it makes things worse. Of course, normally you would use something like a try/catch for exceptional conditions but even her it is not always easy to remember to close all the resources and in multithreaded code it becomes even more complex ( there used to be a way in java to stop a thread but this was removed due to it being inherently unsafe.). I've run into this with ctrl-C, my sacred stop all seems to kill R and leave R term or something so cygwin ends up sending some commands to bash and some to R until I kill Rterm in task manager. I always assume I have ctrl-C in my script based data analysis as you really can't always know how long you want things to go in with exploratory work ( put ctrl-C in a prespecified analysis plan and see how that goes over LOL).
From: Marius Hofert
Date: Sat, 15 Jan 2011 09:09:20 +0100
Dear expeRts,
is there a neat way to *completely* stop a script after an error
occured? For example, consider the following script:
## ==== file.R ====
for(i in 1:10){
print(i)
if(i == 5) stop("i == 5")
}
for(i in 11:100) print(i)
## ================
stop() behaves like it should namely to stop the execution of the
*current* expression, but I was wondering if it is possible to *really*
stop the script after the first for loop [so without executing the
second for loop or anything after that point]. Of course one could use
something like "if(there was an error) do not continue" but that's not
really nice.
______________________________________________ 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.