Vandenman Vandenman - 10 months ago 59
R Question

DEoptim appears to freeze in R

I have encountered a situation where

appears to freeze. I can't figure out why and was hoping somebody with more experience in C could take a look at it.

It is rather difficult to create a reproducible example, so I simply saved the entire environment 50 iterations before the DEoptim freezes. The file below,
can be found here.

rm(list = ls())

load('Envir650.Rdata') # load the environment

# Adjust one function
argsList$fun.density = DstarM::Voss.density

argsList$control$trace = 1 # show intermediate output
argsList$control$parallelType = 0 # don't use parallel processing
.Random.seed = randomseed # set seed

out =, argsList) # freezes at iteration 21 and crashes R.

Many thanks in advance!

EDIT: I hope the problem is now reproducible.


The problem is in rtdists package, source file density.c, function integrate. The loop

for(x = a+0.5*step; x < b; x += step) {
    result += step * F->f(x, F->data);

becomes infinite because step is too small. It is so small that x+step==x and x never reaches b. The code of integrate should be changed so that step is never smaller than EPSILON:

--- orig/rtdists/src/density.c  2016-07-15 10:28:56.000000000 +0200
+++ mine/rtdists/src/density.c  2016-08-29 17:41:53.831078335 +0200
@@ -72 +72 @@
-   double step = width / N;
+   double step = fmax(width / N, EPSILON);

With this change applied, your example finishes at iteration 51 without looping or crashing. I've notified the rtdists authors; the fix is now in the github version of the package.