title: Cauchy principal value numerical integration
body: <p>I'm using R's integrate function, but the integrand is giving me some trouble (it has a singularity). Consider this,</p>
  
  <pre><code>distrib &lt;- function(x){
    dnorm(x, mean=700,sd=50)
  }
  
  phi &lt;- function(nu, epsilon=20, maxi=Inf){
  
    fun &lt;- function(nup)  {
      lambdap &lt;- 1e7/nup
      distrib(lambdap) / (nup*(nup - nu))
    }
    # first part: from epsilon to nu - epsilon
    I1 &lt;- integrate(fun, epsilon, nu-epsilon, rel.tol = 1e-8,
                    subdivisions = 200L)
    # second part: from nu + epsilon to Infty
    I2 &lt;- integrate(fun, nu+epsilon, maxi, rel.tol = 1e-8, 
                    subdivisions = 200L)
  
    I1$value + I2$value 
  
  }
  
  
  x &lt;- seq(1e7/500, 1e7/1000, length=200)
  
  phi1 &lt;- sapply(x, phi)    
  phi1 &lt;- sapply(x, phi, epsilon=5)
  #Error in integrate(fun, epsilon, nu - epsilon, rel.tol = 1e-08, subdivisions = #200L) : 
  #  the integral is probably divergent
  </code></pre>
  
  <p>Is there a better way of calculating such principal values in R, than playing with a cutoff parameter and adjusting it manually until it gives a result (not necessarily accurate)?</p>