1

I promise I'm not an expert of sites policy and that all the information that I'll eventually get will be used for didactical studies, as I'm a student.

My purpose is to get a sequence of images of a web page (on which i will apply techniques of image recognition in future). I thought to write some lines of code in R to make the pc automatically make screenshots at certain times.

I thought that Rpackages taskscheduleR and webshot might work for me.

I wrote a first script which is the scheduler:

library(taskscheduleR)
myscript <- system.file("extdata", "shooter.R", package = "taskscheduleR") 

## run script
taskscheduler_create(taskname = "SCHEDULE_TRAINING", rscript = myscript,  
                     schedule = "MINUTE", starttime = format(Sys.time() + 5, 
                     "%H:%M"))

## delete the tasks
taskscheduler_delete(taskname = "SCHEDULE_TRAINING")

and then i wrote a second script which makes the screenshot (shooter.R):

library(webshot)
#webshot::install_phantomjs() # only the first time 

URL="https://www.hattrick.org"

time0=gsub(":","",Sys.time())
time=gsub(" ","",time0)
out=paste(time,".png",sep="")

webshot(URL, out, delay=1)

The second script works if I execute it individually and the screenshot appears in my folder, although if I execute the script through the first script it doesn't work (even if in the output I don't get any error) and no screenshots appear.

Someone could help me or knows something alternative I can do to reach my goal?

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • Possible duplicate of [failure in saving images through taskscheduler R](https://stackoverflow.com/questions/47886517/failure-in-saving-images-through-taskscheduler-r) – pogibas Dec 20 '17 at 09:52

1 Answers1

1

Create new notepad and write below and save it to r.bat

start /min T:\Repository\Mehul\shooter.R
  • Avoid space in path.
  • Write full path of r script.
  • When you create schedule task run r.bat instead of shooter.R
  • Set r script to run on default program in Rscript.exe that will be find from ..\R-3.4.3\bin\Rscript.exe
Mehul Katara
  • 907
  • 11
  • 32
  • Ok, i've done, but the r.rmd only opens shooter.R in R but it doesn't execute it. How can i do to make r.rmd also execute the she script? Thank you! – Francesco Dal Pont Dec 20 '17 at 22:15
  • you need to set default program run for r script. right click on r script and select open with and find Rscript.exe you file find it from ..\R-3.4.3\bin\Rscript.exe – Mehul Katara Dec 21 '17 at 06:25