John Richardson
John Richardson

Reputation: 696

Wait for file to exist

Is there a way in R to pause execution of a script until a file is created? I would like to pre-load R in advance to decrease the execution time when the input file is generated.

Upvotes: 7

Views: 4456

Answers (1)

josliber
josliber

Reputation: 44340

If you want to keep this in R, you might try the following code:

while (!file.exists(your.file.name)) {
  Sys.sleep(1)
}

A shorter sleep duration would poll more frequently but might be slightly more CPU intensive.

Upvotes: 12

Related Questions