title: Stop executing code in R
body: <p>I use data checks in my code, for example the following one:</p>
  
  <pre><code>if (...)
  stop(paste('Warning: Weights do not sum up to 1')
  </code></pre>
  
  <p>The problem is that if the condition is true and the warning appears in the console, the code does not stop running. If hidden in a long code, one needs to scroll up always in the console output to see if a warning appeared.</p>
  
  <p>Is there a way to tell R to interupt ALL code when the stop warning appears and the condition is true? Something like BREAK ?</p>
  
  <p>I do not represent a reproducible example here because my code is quite long.</p>
  
  <p>EDIT:</p>
  
  <p>Here is a mini example:</p>
  
  <p>When I execute</p>
  
  <pre><code>a=1+2
  
  if (a==3)
    stop('a equals 3')
  
  
  b=4
  
  1+1
  </code></pre>
  
  <p>I would like to stop after printing</p>
  
  <pre><code>&gt; a=1+2
  &gt; 
  &gt; if (a==3)
  +   stop('a equals 3')
  Error: a equals 3
  </code></pre>
  
  <p>but R executes everything, also the last part:</p>
  
  <pre><code>&gt; a=1+2
  &gt; 
  &gt; if (a==3)
  +   stop('a equals 3')
  Error: a equals 3
  &gt;        
  &gt;        
  &gt; b=4
  &gt; 
  &gt; 1+1
  [1] 2
  </code></pre>