Chapter 27 Cancel handling

Accepting cancellation from user

CheckUserInterrupt() function checks if the ‘ctrl + c’ button was pressed, and if it was pressed it will stop the execution of the function.

If you want to execute a calculation that takes a long time, you would be better to run checkUserInterrupt() approximately once every few seconds.

for (int i=0; i<100000; ++i) {
    // Checking interruption every 1000 iterations
    if (i % 1000 == 0){
        Rcpp::checkUserInterrupt();
    }

    // do something ...
}