I am trying to set up a task that runs a batch-file, that runs a .rmd
file which should knitr me a lovely .html
file each day.
Everything works fine, if I run the batch-file manually. However, when I run it through the task scheduler, I get the following error from the command prompt:
Error in file(con, "w") : cannot open the connection
Calls: <Anonymous> -> knit -> writeLines -> file
In addition: Warning message:
In file<con, "w") : cannot open file 'residual_v1.md" : Permission denied
Execution halted
The same user is listed as the "author" in the task-scheduler, as the user when you open the start menu.
Batch-file code:
"C:\R\R-3.0.3\bin\x64\Rscript.exe" -e "library(knitr,dplyr); knitr::knit2html('C:/R/Rapporter/residual_model/Residual_v1.Rmd')"
Im am at a loss of what to do.
In "Last run result" field of Task Scheduler I get a strange error 0x41301. I googled it and discovered that it means "Task is already running". Surprisingly I found this program in running tasks just after system boot but no GUI is shown. Only the process itself is running.
In recent versions of RStudio (0.99. 893 or later), select Addins and next select 'Schedule R scripts on Windows'. This will allow you to select a script to be scheduled at your specified timepoints. The script will be copied to the Rscript repo folder and will be launched from there each time.
It looks you do not have write permission in the working directory of R. I'd recommend you to set the working directory before you run knit2html()
, e.g.
setwd('C:/R/Rapporter/residual_model/')
knitr::knit2html('Residual_v1.Rmd')
i.e.
"C:\R\R-3.0.3\bin\x64\Rscript.exe" -e "setwd('C:/R/Rapporter/residual_model/'); knitr::knit2html('Residual_v1.Rmd')"
Or any other output directory in which you have write permission:
setwd('any/output/directory/you/want')
knitr::knit2html('C:/R/Rapporter/residual_model/Residual_v1.Rmd')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With