title: Argument checking in R
body: <p>In R, I wrote a function like:</p>
  
  <pre><code>fun &lt;- function(A, B, C, D) {}
  </code></pre>
  
  <p>So, at the beginning of this function, I must do argument checking:</p>
  
  <ul>
  <li>Is some required arguments missing</li>
  <li>Is all arguments following the rules: <strong>class(data type)</strong> or <strong>A must be in range [1:3]</strong></li>
  </ul>
  
  <p>But about these arguments, some are required, some are not, and the <strong>class(data type)</strong> of each argument must be what I want, for example: <strong>numeric</strong>, <strong>logical</strong>, and so on...</p>
  
  <p>To accomplish this, I did things like： </p>
  
  <pre><code>if(A Follow_the_rule){}
  if(B Follow_the_rule){}
  if(C Follow_the_rule){}
  ...
  </code></pre>
  
  <p>About the code above, so much <strong>if</strong> statements are required which I think isn't the best way of argument checking.</p>
  
  <p>So <strong>Is there a better way to check arguments in R?</strong></p>
  
  <p>Any help will be appreciated.</p>