I wrote an R script that pulled data from an RSS feed. The RSS feed updated frequently, so I wanted to be able to schedule the script to run automatically. After some tinkering, I got it to work by implementing the steps below. Note that these steps assume you do not want to save your workspace – that you are saving the objects you need explicitly within the script.
|Step 3: The Run Shell Script Action|
- Test your R script in regular ole’ R to make sure it runs without error.
- Add a quit(save=”no”) command at the end of your script.
- Open Automator (Applications -> Automator)
- Select Application from the Template Selection menu
- Select the Run Shell Script Action, double click or drag it over
- Type: Rscript –no-save –no-restore /Users…./YourScript.R
- The last argument should be the path of the script file you want to run
- The 2nd and 3rd arguments tell R not to save the workspace when it’s done and not to restore previously saved objects on startup, respectively
- To see a full list of arguments you can pass to Rscript, just open Terminal and type Rscript
That’s it, you’re done. When the scheduled time comes, the script will run in the background without even opening R. You may see a little gear up top on your menu bar, that’s it.