R Not Responding Request to Interrupt Stop Process

R not responding request to interrupt stop process

Unfortunately, RStudio is currently not able to interrupt R in a couple situations:

  1. R is executing an external program (e.g. you cannot interrupt system("sleep 10")),

  2. R is executing (for example) a C / C++ library call that doesn't provide R an opportunity to check for interrupts.

In such a case, the only option is to forcefully kill the R process -- hopefully this is something that could change in a future iteration of RStudio.


EDIT: RStudio v1.2 should now better handle interrupts in many of these contexts.

Stop submitted lines of code from running

Assuming you're running in console (or interactive session in R studio, that's undetermined from your question) and that what you did was sourcing a script/pasting code and while it was running pasting another chunck of code:

What is ongoing is that you pushed data into R process input stream, it's a buffered input, so it will run each line once the previous line call has ended and free the process.

There's no easy way to play with an input buffer, that's R internal input/output system and mostly it's the Operating system which have those information in cache for now.

Asking R itself is not possible as it already has this buffer to read, any new command would go after.

Last chance thing: If you can spot your another chunck of code starting in your console, you can try pressing the esc key to stop the code running.

You may try messing with the process buffers with procexp but there's a fair chance to just make your R session segfault anyway.

To avoid that in the future, use scripts and run them on the command line separately with Rscript (present in R bin directory under windows too despite the link pointing to a linux manpage).

This would create one session per script and allow to kill them independently. That said if they both write to the same place (database, a file would create an error if accessed by two process) that won't prevent data corruption.

How to stop an R program using Rcpp midway in Rstudio on MacOS?

You can use Rcpp::checkUserInterrupt(). For example:

#include <unistd.h>
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
void forever() {

try
{
for (int i = 0; ; i++)
{
Rcout << "Iteration: " << i << std::endl;
::sleep(1);
Rcpp::checkUserInterrupt();
}
}
catch (Rcpp::internal::InterruptedException& e)
{
Rcout << "Caught an interrupt!" << std::endl;
}

}

/*** R
forever()
*/

If you attempt to interrupt R while this is running you should see something like:

> Rcpp::sourceCpp('scratch/interrupt.cpp')
> forever()
Iteration: 0
Iteration: 1
Iteration: 2

Caught an interrupt!

Note that the try-catch block is unnecessary if you're using Rcpp attributes as the associated try-catch exception handlers will automagically be generated in a wrapper function for you. I just add them here to illustrate that Rcpp responds to interrupts with this API by throwing a special exception.

How to stop a command in R in Windows

When running a code, the red octagon will only show while it is working things out. So while it is just running through your written code (reading data and names of things etc) then the octagon will not show.

Pressing ESC will work, unless Rstudio is frozen.

Good luck!



Related Topics



Leave a reply



Submit