Reputation: 11686
I have a function that potentially can take quite a long time.
I was wondering if there is a cleaner way to stop the function other than something like this:
repeat{
time1 <- Sys.time()
myfunction(x,y,z,...)
time2 <- Sys.time()
if(time2 - time1 > my.time.limit) {
break
}
}
Upvotes: 2
Views: 336
Reputation: 49820
There is an evalWithTimeout
function in the R.utils package. You can use it like this:
require("R.utils")
evalWithTimeout({
repeat{
myfunction(x,y,z,...)
}
}, timeout=my.time.limit, onTimeout="warning")
Run example(evalWithTimeout)
to see other ways to use it.
Upvotes: 6