简体   繁体   English

R 文件未作为 .bat 文件运行

[英]R file not running as .bat file

I have created a script that I can run in R Studio without issue.我创建了一个脚本,可以在 R Studio 中毫无问题地运行。

I then created a.bat file to run the script which uses this code:然后我创建了一个 .bat 文件来运行使用此代码的脚本:

@echo on
"C:\R\R-4.0.4\bin\x64\R.exe" CMD BATCH C:\Documents\RScript.R

I have used this exact syntax to run R scripts in the past without issue, but for my new R script, it isn't working.我过去曾使用这种确切的语法来运行 R 脚本而没有问题,但是对于我的新 R 脚本,它不起作用。

I can't figure out what is wrong since the R code works when run in R and the.bat code work when run on other R scripts.我不知道出了什么问题,因为 R 代码在 R 中运行时有效,而.bat 代码在其他 R 脚本上运行时有效。 There is no error message -- CMD opens up, shows the.bat command for a bit, and then goes away without an error message.没有错误消息——CMD 打开,显示 .bat 命令一会儿,然后消失,没有错误消息。

The R script in question is fairly complex, but some relevant information might be that it:有问题的 R 脚本相当复杂,但一些相关信息可能是:

  • Uses read_csv to check an on-device file and write_csv to update it使用 read_csv 检查设备上的文件并使用 write_csv 更新它
  • Uses read_csv to check a publicly-editable Google Sheets document consisting of URL and e-mail addresses使用 read_csv 检查由 URL 和电子邮件地址组成的可公开编辑的 Google 表格文档
  • Uses rvest for web scraping those URLs对 web 使用 rvest 来抓取这些 URL
  • Uses gmailr to e-mail the results to any e-mail addresses included in the spreadsheet使用 gmailr 将结果通过电子邮件发送到电子表格中包含的任何电子邮件地址

My hunch is that the issue is related to these packages, since they access content that isn't stored on my machine.我的预感是问题与这些软件包有关,因为它们访问的内容未存储在我的机器上。

Anyone know what to do?有谁知道该怎么做?

Nevermind, figured it out.没关系,想通了。

If anyone else has this problem, check the.Rout file that is outputted.如果其他人有这个问题,请检查输出的 .Rout 文件。 It may be returning error messages.它可能会返回错误消息。

In my case, there were packages that were not being added with library() before running the script.就我而言,在运行脚本之前,有些包没有被 library() 添加。

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

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