I am using Rscript more and more where I would have normally used bash scripts. One small annoyance is that many of these scripts loop over some system()
call that leaves basically no time for R to catch my control-c if I try to interrupt it. Instead it just aborts the system command that was running and continues on to the next loop iteration. For example, when I try to interrupt the following by holding down control-c, it still makes it through all the iterations:
for(i in 1:10) {
cat(i)
system('sleep 3')
}
So far I have always just hacked around this by inserting a small pause in each loop like
for(i in 1:10) {
Sys.sleep(0.25)
cat(i)
system('sleep 3')
}
that will let me abort within an iteration or two if I hold down control-c, but I'm wondering, is there a more efficient way to accomplish this behavior?