Tho*_*rst 5 r batch-file knitr
我正在尝试设置一个运行批处理文件的任务,该文件运行的.rmd文件应该每天编织一个可爱的.html文件.
如果我手动运行批处理文件,一切正常.但是,当我通过任务计划程序运行它时,我从命令提示符处收到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
在打开开始菜单时,同一用户在任务调度程序中列为"作者".
批处理文件代码:
"C:\R\R-3.0.3\bin\x64\Rscript.exe" -e "library(knitr,dplyr); knitr::knit2html('C:/R/Rapporter/residual_model/Residual_v1.Rmd')"
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么办.
它看起来你没有R的工作目录中的写权限.我建议你在运行之前设置工作目录knit2html(),例如
setwd('C:/R/Rapporter/residual_model/')
knitr::knit2html('Residual_v1.Rmd')
Run Code Online (Sandbox Code Playgroud)
即
"C:\R\R-3.0.3\bin\x64\Rscript.exe" -e "setwd('C:/R/Rapporter/residual_model/'); knitr::knit2html('Residual_v1.Rmd')"
Run Code Online (Sandbox Code Playgroud)
或者您拥有写入权限的任何其他输出目录:
setwd('any/output/directory/you/want')
knitr::knit2html('C:/R/Rapporter/residual_model/Residual_v1.Rmd')
Run Code Online (Sandbox Code Playgroud)