title: using a user defined function in Rcpp (cppFunction)
body: <p>I have a user defined function in r:</p>
  
  <pre><code>blacksch&lt;-function(s_0,k,sigma,r,t)
  {
    d1=(log(s_0/k) + (r + (sigma^2)/2)*(t))/(sigma*sqrt(t))
    d2=(log(s_0/k) + (r - (sigma^2)/2)*(t))/(sigma*sqrt(t))
  
    p=(pnorm(-d2)*k*exp(-r*t))-pnorm(-d1)*s_0
  }
  </code></pre>
  
  <p>And I would like to use this function in c++ code that I have written using Rcpp and cppFunction.  I have been through the documentation and examples a few times, but have not been successful.</p>
  
  <pre><code>bs_martin&lt;-cppFunction('NumericMatrix compMartin (NumericMatrix st, NumericMatrix dv, double s_0, double k, 
                         double t, double sigma, double r, int steps, int paths, Function blacksch(fun)) {
  
                         // Ensure RNG scope set
                         RNGScope scope;
  
  
          int min_bs_step=0;
          double minbsvalue=0;
          vector&lt;double&gt; u[0]=100.0;
          for(int i=1;i&lt;=paths; i++)
          {
            min_bs_step=0;
            for(int j=1;j&lt;=steps;j++)
            {
              if (dv[i,j]&gt;0 &amp;&amp; min_bs_step==0)
              {
                  min_bs_step=i;
                  minbsvalue=blacksch(s_0,k,sigma,r,t);
              }
              else if (min_bs_step!=0)
              {
                  dv[i,j]=1 - minbsvalue;
              }
            }
  
          }
        return dv;
                         }')
  </code></pre>