Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knitr-error from Task Schedule Manager

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.

like image 215
Thorst Avatar asked Jul 11 '14 06:07

Thorst


People also ask

What is 0x41301 in Task Scheduler?

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.

Can you schedule an R script to run?

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.


1 Answers

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')
like image 144
Yihui Xie Avatar answered Oct 16 '22 09:10

Yihui Xie