title: R multiple integrals
body: <p>I have a four integrals like this:</p>
  
  <p><a href="https://i.stack.imgur.com/2yxul.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2yxul.png" alt="enter image description here"></a></p>
  
  <p>To calculate this function, my R code is as follows:</p>
  
  <pre><code>tol &lt;- 1e-05
  t.cutoff = 1e-15
  
  integrand &lt;- function(kappa, sigma, eta, tau) sqrt((tau-eta)/(sigma-kappa))*exp(-(sigma-kappa))
  
  integrate1 &lt;- function(sigma, eta, tau) integrate(integrand, tol * sigma, (1 - tol) * sigma, sigma = sigma, eta = eta, tau = tau)$value
  integrate1.vec &lt;- function(sigma, eta, tau) mapply(integrate1, sigma, eta, tau)
  
  integrate2 &lt;- function(eta, tau) integrate(integrate1.vec, tol * eta, (1 - tol) * eta, eta = eta, tau = tau)$value
  integrate2.vec &lt;- function(eta, tau) mapply(integrate2, eta, tau)
  
  integrate3 &lt;- function(tau) integrate(integrate2.vec, tol * tau, (1 - tol) * tau, tau = tau)$value
  integrate3.vec &lt;- function(tau) mapply(integrate3, tau)
  
  
  c_t &lt;- function(t) ifelse(t &gt; t.cutoff, integrate(integrate3.vec, tol * t, (1 - tol) * t)$value, 0)
  
  c_t(1)
  </code></pre>
  
  <p>I think my above code is low efficient; I wonder if there is any improvement or available package for this kind of integrals. Thanks in advance!</p>