title: How to quit R script when an error occurred
body: <p>I am writing an R script as a command to run in terminal, and I found if an error happen when running this script, the command still returns a normal exit signal. So I cannot check the running results by checking <code>[ $? -ne 0 ]</code>, it just returns <code>succeed</code>.</p>
  <p><a href="https://i.stack.imgur.com/7K77g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7K77g.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/BVFvl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BVFvl.png" alt="enter image description here" /></a></p>
  <p>This is because R will continue running the next command when it encounters an error in previous command. Is there any way to solve this situation?</p>
  <p>Best,</p>
  <p>Shixiang</p>