Alexander Engelhardt
Alexander Engelhardt

Reputation: 1712

In R, how can I schedule function execution in a cronjob-like way?

I would like to write an R script that runs for the whole day. It should basically be an infinite loop that fetches trading data, applies smart stuff to it, and uploads the trading data somewhere else again.

I'm thinking about starting the script at 8:30am, then it would automatically "do nothing" until 9:00am, then start running in a loop until 5:00pm, and then idle again, until I shut down the R session.

What's the best way to achieve this behavior?

I have no access to Linux machines, so multiple scripts and cronjobs are not possible, unfortunately.

Upvotes: 1

Views: 464

Answers (3)

Damien Cormann
Damien Cormann

Reputation: 189

 while ( as.numeric(format(Sys.time(),format =  "%H")) %in% 8:17){
if(as.numeric(format(Sys.time(),format =  "%H")) %in% 9:17){ 
# your code here
}
}

Upvotes: 2

ivivek_ngs
ivivek_ngs

Reputation: 937

You can take a look at this link

Windows Task scheduler can do the task

Even with Rstudio you can Some more links here and here Link Then the package taskschedulR

Upvotes: 2

WHoekstra
WHoekstra

Reputation: 173

If you're on a Windows consumer platform, you could use the 'scheduleR' package. Otherwise, if you're on a Windows Server, then you could use the Windows Scheduler.

Upvotes: 1

Related Questions