title: double integration in R with additional argument
body: <p>I learned in this question <a href="https://stackoverflow.com/questions/8913603/calculating-double-integrals-in-r-quickly">calculating double integrals in R quickly</a> how to do double integral.</p>
  
  <p>My problem is when there is one more argument of the function.
  Please see the example.</p>
  
  <pre><code>z = 2
  fun0 = function(x,y) { tan(x+y)*z }
  fun01 = integrate(function(y) { 
     sapply(y, function(y) {
        integrate(function(x) fun0(x,y), -.5, y)$value
     })
  }, 0, .5)$value
  </code></pre>
  
  <p>The result is as follows.</p>
  
  <pre><code> &gt; fun01
  [1] 0.1447771
  </code></pre>
  
  <p>I would like to make this 'fun01' to a function of z.</p>