简体   繁体   English

.BAT文件R脚本中的错误

[英]Error in .BAT file R Script

I have a .bat file as follows. 我有一个.bat文件,如下所示。 task.bat task.bat

@echo off
R CMD BATCH C:\Users\Raghavan\Desktop\MyTask.R

The file needs to run an R script. 该文件需要运行R脚本。 The following is the R script. 以下是R脚本。

 A<-read.csv("C:\Users\Raghavan\Desktop\A.csv")
 write.csv(A, file = "B.csv")

The R script runs by itself. R脚本自行运行。 However, when I try running it through the .bat file or through windows scheduler, the script fails to run. 但是,当我尝试通过.bat文件或Windows Scheduler运行它时,脚本无法运行。 I have tried many sites.I request someoen to see if this error can be fixed. 我已经尝试了许多站点。我要求进行一些检查,看看是否可以修复此错误。 Most likely, the error is in the .bat file 该错误最有可能在.bat文件中

I run my R files with the following command inside of the .bat script: 我在.bat脚本中使用以下命令运行R文件:

@echo Off
"C:\Program Files\R\R-3.4.2\bin\R.exe" CMD BATCH --vanilla --slave "C:\File.R"

Define the full paths to executable R and to the file that you wanna run. 定义可执行文件R和要运行的文件的完整路径。 Hope this helps. 希望这可以帮助。

See also ?BATCH and this resource on arguments of R CMD BATCH. 另请参见?BATCH和有关R CMD BATCH的参数的资源

I made the following edits to the code. 我对代码进行了以下编辑。

  @ echo off
  "C:\Program Files\R\R-3.3.2\bin\R.exe"  R CMD BATCH "D:\Newfolder\task1.R"

The files were then shifted to the D drive. 然后将文件转移到D驱动器。 This resulted in the code working. 这导致代码正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM