title: How can I discriminate between functions in R
body: <p>I have been trying to write a code capable of using different classification functions. However, the arguments are different depending on the classification function I use. I would like to have something like this :</p>
  
  <pre><code>classification_flow &lt;- function(classification_function, ...) {
      if (classification_function == randomForest) {
          ...
      } 
      else if (classification_function == svm) {
          ...
      }
  }
  </code></pre>
  
  <p>Of course, this doesn't work since <code>==</code> wasn't built for functions. I've tried using <code>str</code>, <code>names</code>, <code>attr</code>, and looked a bit at <code>methods</code>and <code>UseMethod</code>, but I can't find a suitable way to do so.</p>
  
  <p>Can anybody help me?</p>
  
  <p>Thanks,<br>
  Jess</p>
  
  <p>PS : In this particular case, what I'm trying to do is to get a matrix of probabilities as the output, so something like that : </p>
  
  <pre><code>classification_flow &lt;- function(classification_function, train, classes, ...) {
      if (classification_function == randomForest) {
          mat = classification_function(train, classes, type="prob")
      } 
      else if (classification_function == svm) {
          mat = classification_function(train, classes, probabilities = T)
      }
      return(mat)
  }
  </code></pre>
  
  <p>If you know a more elegant solution...</p>