7

I would like to run a script every 30 min from my local comp. Most of the time I am away from my desk. I do not want to run my computer all day. What would be some ways to do this.

Currently I have the following code. The code works perfectly while my computer is running.

library(taskscheduleR)

taskscheduler_create("docu", 
"C:/Users/jorda/OneDrive/Documents/first.R", 
"MINUTE", "23:15", modifier = 30, startdate = "2019/06/05")

Note* I am using windows 10.

The ideal solution would be for the computer to wake up to run the code and then go back to sleep.

I am using this video for guidance https://www.youtube.com/watch?v=UDKy5_SQy2o&t=213s

I have a folder called task which currently holds 2 children: firstschedule.R and task1.bat. My .bat file is:

@echo off
R CMD BATCH #path to my file

When I try to open the file I get a pop up that says - Run as administrator or another user. After clicking run as administrator, I get another pop up that asks me if windows can make changes to my computer. After clicking allow. Nothing happens. I was expecting an output log to pop up with all the outputs. My R script is simple

x=10
y = x + 5
print(y)

here is a similar more up to date tutorial. https://www.r-bloggers.com/how-to-run-r-from-the-task-scheduler/ It seems I am having a hard time locating this Rscript file. Is it something that was used in older versions of R but not for the current 3.6.0?

I am not to sure what I am doing wrong here. Thank you. enter image description here

TylerH
  • 20,799
  • 66
  • 75
  • 101
Jordan Wrong
  • 1,205
  • 1
  • 12
  • 32
  • Have you tried using the task scheduler from the Windows 10 side? A couple years ago I tried what you are trying and had the same problem. My solution was to take the R script and set up the job from windows, and then it ran regularly when I wasn't at my computer whether the computer was on or off. Hope this helps. – mysteRious Jun 06 '19 at 04:40
  • Hi @mysteRious, thanks for response. I have not tried this. Do you have a link to a video/paper that demonstrates how to do this? I read a link on quora where someone was able to do what you mentioned and got it working! If you do not have a link, could I bother you for some more color? – Jordan Wrong Jun 06 '19 at 04:45
  • 2
    This is the method I used... guy in the video has a much more complicated R script that's rendering an Rmd -- but the technique of writing the stub batch file and handing it to task scheduler is almost the same: https://www.youtube.com/watch?v=UDKy5_SQy2o – mysteRious Jun 06 '19 at 05:01
  • I haven't seen anyone mention the "wake computer" feature of Windows scheduled tasks. See screenshot: https://i.stack.imgur.com/LMuwK.png There is probably some way to check that box with code. – daveloyall Dec 13 '19 at 22:48
  • From this excellent [post](https://www.technipages.com/schedule-windows-10-to-wake-from-sleep-automatically). In Windows 10 Task Scheduler to use "wake computer" feature as @daveloyall mentioned in comments, we have to ensure your power plan is configured to allow wake timers. Edit your current power plan options at "Control Panel\Hardware and Sound\Power Options\Edit Plan Settings". In the advanced power plan settings, ensure that the allow wake timers option is enabled under “Sleep > Allow wake timers.”. Now, you can setup a task from Task Scheduler with wake time. – A. Suliman Jun 02 '20 at 09:37

0 Answers0