0

I'm trying to source multiple R scripts with a short delay in between each one. The 15 R scripts to be 'sourced' all collect data from GA API, transform/clean/analyze the data, then finally push the into their own worksheets within a single Google Sheet. So I'd like to set a wait of 1 minute between each script to make sure I'm not overloading the Google Sheet file.

How can I turn the code (below) into a mini-function where there is a wait time between each source() command?

    source("/code/processed/script1.R")
    source("/code/processed/script1.R")
    source("/code/processed/script1.R")
    ...
    source("/code/processed/script15.R")

Thanks in advance for your help! :)

PS - For context, please note I have my working directory organized in the following hierarchy:

 |-project  
    |-code  
      |-processed  
      |-raw  
    |-data  
      |-processed  
      |-raw  
hianalytics
  • 313
  • 3
  • 11
  • 1
    Does the answer on this question helps? http://stackoverflow.com/questions/1174799/how-to-make-execution-pause-sleep-wait-for-x-seconds-in-r – Wannes Rosiers Jul 24 '15 at 14:13
  • @WannesRosiers - yes, it's helpful thank you. but I'm not yet understanding how I can add the `source()` command to the function to have it cycle through all 15 with a 60 second pause between each. – hianalytics Jul 24 '15 at 15:28

1 Answers1

1

As suggested in my comment I would use sys.sleep(), either by manually adding it netwerk every source command:

source(...)
sys.sleep(60)
source(...)

Or by storing all scripts in a vector and looping over them.

Wannes Rosiers
  • 1,680
  • 1
  • 12
  • 18