Code to stop the execution of another code

I have code Rthat does some data analysis and returns TRUE/FALSE. Sometimes the input is too large and the code just keeps working.

I want the script to track my data analysis code, and if it returns nothing, say 600 seconds, then it stops the current code and does something else.

It will be like pressing a button STOPon R console.

I am aware of STOP, break, exitetc. But they will not be useful, because the code will not reach these statements, because it still starts its data analysis cycle.

+4
source share
3 answers

setTimeLimit() script script, .

setTimeLimit(elapsed = 10)
for(i in c(1:100)){
    cat(i,"\n")
    Sys.sleep(1)
}

, , . 10 , , 100, .

+6

script , Linux ulimit -t 300 , , Rscript code.R.

​​ , 300 . , , ulimit.

0

. , , , 10 000 .

When I do this inside the loop, I hide

k <- k  + 1 
print(k)

so I can track my code and see how much I have already done. Ofcoruse you can improve this and keep track of the time between each I in a cycle with proc.time (

0
source

All Articles