Return current data when user interrupts R

Is it possible to return data from the current iteration when the user interrupts R?

Sort of:

if (user.aborts == TRUE) { return(data) } 

This would be really useful, since the input for this procedure is just the data. Then it can be broken and continued after that.

+4
source share
1 answer

Perhaps if you want to manually stop the process, for example,

 myfun <- function(x){ on.exit(return(x)) for(i in 1:5){ x <- x + 1 Sys.sleep(1) } } x <- myfun(1) # Stopping before it finishes x [1] 4 
+5
source

Source: https://habr.com/ru/post/1484379/


All Articles