title: How to exit(0) in R?
body: <p>I work in RStudio and I need to exit my code (BUT not the RStudio session) from inside a function, when it meets a specific condition, e.g. a key press. In C/c++, we use <code>exit(0)</code> function to do that. In R, if I call <code>quit()</code>, it attempts to close the entire R session for me, but I just need to stop executing current coding from inside my function.</p>
  
  <p>I.e. I'm looking for function like below, which would cause the program to exit, when user enters 'q'.</p>
  
  <pre><code> f &lt;- function() {  
      if (readline("Press 'q' to exit the code: ") == 'q') 
         #I want to terminate the execution of program here
     else 
          #continue the execution of other set of commands
   }
  </code></pre>
  
  <p>Help me achieve this</p>