If you consider the integral on an interval centered on the singularity, you can use a change of variable to symmetrize the integrand: the singularity disappears, as detailed in the paper Numerical evaluation of a generalized Cauchy principal value (A. Nyiri and L. Bayanyi, 1999).
# Principal value of \( \int_{x_0-a}^{x_0+a} \dfrac{ f(x) }{ h(x) - h(x0) } dx \)
pv_integrate <- function( f, h, x0, a, epsilon = 1e-6 ) {
# Estimate the derivatives of f and h
f1 <- ( f(x0+epsilon) - f(x0-epsilon) ) / ( 2 * epsilon )
h1 <- ( h(x0+epsilon) - h(x0-epsilon) ) / ( 2 * epsilon )
h2 <- ( h(x0+epsilon) + h(x0-epsilon) - 2 * h(x0) ) / epsilon^2
# Function to integrate.
# We just "symmetrize" the integrand, to get rid of the singularity,
# but, to be able to integrate it numerically,
# we have to provide a value at the singularity.
# Details: http://mat76.mat.uni-miskolc.hu/~mnotes/downloader.php?article=mmn_16.pdf
g <- function(u)
ifelse( u != 0,
f( x0 - u ) / ( h(x0 - u) - h(x0) ) + f( x0 + u ) / ( h(x0+u) - h(x0) ),
2 * f1 / h1 - f(x0) * h2 / h1^2
)
integrate( g, 0, a )
}
# Compare with the numeric results in the article
pv_integrate( function(x) 1, function(x) x, 0, 1 ) # 0
pv_integrate( function(x) 1, function(x) x^3, 1, .5 ) # -0.3425633
pv_integrate( function(x) exp(x), function(x) x, 0, 1 ) # 2.114502
pv_integrate( function(x) x^2, function(x) x^4, 1, .5 ) # 0.1318667