Skip to content
Back to formatted view

Raw Message

Message-ID: <alpine.DEB.2.00.1101150927270.17549@springer.Berkeley.EDU>
Date: 2011-01-15T17:29:03Z
From: Phil Spector
Subject: How to *completely* stop a script after stop()?
In-Reply-To: <8706830A-B654-4FEF-A87C-7E240F68741C@web.de>

Marius -
    Do you get the behaviour you want if you substitute

     if(i == 5){cat('i==5\n');quit(save='n')}

for the line with the call to stop?


 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Sat, 15 Jan 2011, Marius Hofert wrote:

> 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.
>
> Cheers,
>
> Marius
> ______________________________________________
> 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.
>