I have an R project which uses Rcpp for long simulations. When I try to stop such a program (e.g. it is taking too long or I am no longer interested in those results) using in Rstudio, then Rstudio crashes. Essentially I am looking for a way to kill the Rcpp function without crashing Rstudio so that I can run it again with some different parameters without losing variables in the R environment (when R studio crashes). I can save and load the environment before calling the function but I am hoping there might be an elegant solution. Any suggestions?
Here is an example.
testR <- function(){
i=1
while(i>0){}}
Another function in a C++ file
// [[Rcpp::export]]
int testCpp( ) {
double x=3;
do{
} while (x>0);
return x;
}
When I call testR
and then click on the red stop icon in the console then it exits normally.
Instead, if I call testCpp
and do the same I receive the following message (I have to press the red stop icon twice as nothing happens if I click it only once). If I click yes, the session is restarted and I lose the variables.
""