Sukhi
Sukhi

Reputation: 836

Run a function every 60 secs in R

I wan to run a function every 60 seconds, until the task is achieved.

I am running scripts on cluster and check every 60 seconds, if they are finished or not. I've parsed in the qstat output but want to run it in a function every 60 secs.

My go: The following line gives me the current second's clock, so the plan was whenever its 0, it runs this function, but doesn't help that much, as the this checking will be static and once or I can try to use an until like function here, but couldn't find that as well

as.numeric(paste(tail(unlist(strsplit(gsub("\\D","",(format(Sys.time(),"%X"))),'')),2),collapse=''))==0)

What you guys think will be most efficient way to run this or any timed function which exists will be helpful.

Thanks

Upvotes: 1

Views: 636

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368231

I would use a cronjob and call R at the desired frequency. And I recommend using littler which has less overhead than either Rscript, or R, and starts quickly. Plus, it is meant for scripts.

The operating system is simply better at scheduling that the (single-threaded !!) application that is R.

Upvotes: 4

Related Questions