Chris vCB
Chris vCB

Reputation: 1053

R - repeated execution of a script

I have an R script that makes certain twitter searches and adds the results, along with a timestamp, to a data frame. What I would like is a way to schedule this script to run every, say, five minutes. Is there a way to do this within R?

Upvotes: 0

Views: 226

Answers (1)

crogg01
crogg01

Reputation: 2516

If you are on a Linux machine you can use cron jobs (link here) on Windows based machines there is a utility called Task Scheduler (link here) which can be used. With those you can call RScript which allows you to execute an R script from the command line (older versions of R on Linux might require you to use R CMD, if so I suggest updating your R). Here is the help from Rscript:

Usage: /path/to/Rscript [--options] [-e expr] file [args]

--options accepted are
  --help              Print usage and exit
  --version           Print version and exit
  --verbose           Print information on progress
  --default-packages=list
                      Where 'list' is a comma-separated set
                        of package names, or 'NULL'
or options to R, in addition to --slave --no-restore, such as
  --save              Do save workspace at the end of the session
  --no-environ        Don't read the site and user environment files
  --no-site-file      Don't read the site-wide Rprofile
  --no-init-file      Don't read the user R profile
  --restore           Do restore previously saved objects at startup
  --vanilla           Combine --no-save, --no-restore, --no-site-file
                        --no-init-file and --no-environ

'file' may contain spaces but not shell metacharacters

The package tcltk2 also allows you to schedule tasks from a running R console using tclTask. So that too is something to consider.

Upvotes: 3

Related Questions