Adaptive quadrature of functions of one variable over a finite or infinite interval.
1 2 3 
f 
An R function taking a numeric first argument and returning a numeric vector of the same length. Returning a nonfinite element will generate an error. 
lower, upper 
The limits of integration. Can be infinite. 
subdivisions 
The maximum number of subintervals. 
rel.tol 
Relative accuracy requested. 
abs.tol 
Absolute accuracy requested. 
stop.on.error 
Logical. If true (the default) an error stops the
function. If false some errors will give a result with a warning in
the 
keep.xy 
Unused. For compatibility with S. 
aux 
Unused. For compatibility with S. 
... 
Additional arguments to be passed to 
This function is just a wrapper around
integrate
to check for equality of
upper
and lower
. A check is made using
all.equal
. When numerical equality is
detected, if lower
(and hence upper
) is infinite, the
value of the integral and the absolute error are both set to 0. When
lower
is finite, the value of the integral is set to 0, and the
absolute error to the average of the function values at upper
and
lower
times the difference between upper
and lower
.
When upper
and lower
are determined to be different, the
result is exactly as given by integrate
.
A list of class "integrate"
with components:
value 
The final estimate of the integral. 
abs.error 
Estimate of the modulus of the absolute error. 
subdivisions 
The number of subintervals produced in the subdivision process. 
message 

call 
The matched call. 
The function integrate
and
all.equal
.
1 2 3 4 5 6 7 8 9 10  integrate(dnorm, 1.96, 1.96)
safeIntegrate(dnorm, 1.96, 1.96) # Same as for integrate()
integrate(dnorm, Inf, Inf)
safeIntegrate(dnorm, Inf, Inf) # Same as for integrate()
integrate(dnorm, 1.96, 1.96) # OK here but can give an error
safeIntegrate(dnorm, 1.96, 1.96)
integrate(dnorm, Inf, Inf)
safeIntegrate(dnorm, Inf, Inf) # Avoids nonsense answer
integrate(dnorm, Inf, Inf)
safeIntegrate(dnorm, Inf, Inf) # Avoids nonsense answer

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.