How to create an empty loop that runs for a given time in R

Viewed 49

I need create an empty loop that runs for a given time, for example 2 hours. The loop just runs for nothing, no matter what it does, it is important that it loads R executions for exactly 2 hours.

for example, let's have some kind of script

model=lm(Sepal.Length~Sepal.Width,data=iris)

after this row there is an empty loop that does something for exactly 2 hours

for i....

after the empty loop has completed via 2 hours, continue to execute subsequent rows

summary(model)
predict(model,iris)

(no matter what row, it is important that in a certain place of code the loop wasted for 2 hours)

How it can be done? Thanks for your help.

1 Answers

There is no need to do this using a loop.

You can simply suspend all execution for n seconds by using Sys.sleep(n). So to suspend for 2 hours you can use Sys.sleep(2*60*60)

Related