来自R&amp导出的.csv;批处理文件 [英] Exporting .csv from R & Batch file

查看:140
本文介绍了来自R&amp导出的.csv;批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每天早上跑R中的报告,我想自动执行此任务。我有一个Windows机器,我已经创建任务计划中的任务。我可以在特定时间运行该文件,但我不能把它导出CSV。我最初的想法是,有正向之间的功放和断开;背斜线,但我不知道在哪里断则。任何人有什么想法?

R_script.R

  setwd('C:/用户/ ME /桌面)
X - 下; - runif(5)
Y'LT; - runif(5)
的xy&下; - data.frame(x = X,Y = y)的
write.csv(XY,'C:/Users/Me/Desktop/xy.csv')

批处理文件

  CMD RSCRIPT批
C:\\用户\\我\\ R_script.R


解决方案

尝试运行您的批处理文件在 CMD 窗口中的第一行。这将导致一个错误:

 > RSCRIPT CMD批
致命错误:无法打开文件CMD:没有这样的文件或目录

如果你使用研究CMD批未检测输入的文件,因为他们应该是在同一行:

 > R CMD批
没有输入文件

代替在这两种方式之一执行的命令,与在同一行上的文件路径:

 > RSCRIPT C:\\用户\\我\\ R_script.R
> R CMD批C:\\用户\\我\\ R_script.R

I run a report in R every morning and I'm trying to automate this task. I have a Windows machine and I've created a task within Task Scheduler. I can get the file to run at a certain time, but I can't get it to export the csv. My initial thoughts is that there is a disconnect between forward- & back-slashes, but I'm not sure where the break is. Anyone have any thoughts?

R_script.R

setwd('C:/Users/Me/Desktop')
x <- runif(5)
y <- runif(5)
xy <- data.frame(X = x, Y = y)
write.csv(xy, 'C:/Users/Me/Desktop/xy.csv')

Batch File

Rscript CMD BATCH
C:\Users\Me\R_script.R

解决方案

Try running the first line of your batch file in a cmd window. It results in an error:

>Rscript CMD BATCH
Fatal error: cannot open file 'CMD': No such file or directory

And if you use R CMD BATCH it doesn't detect the input file because they should be on the same line:

>R CMD BATCH
no input file

Instead run the command in one of these two ways, with the file path on the same line:

>Rscript C:\Users\Me\R_script.R
>R CMD BATCH C:\Users\Me\R_script.R

这篇关于来自R&amp导出的.csv;批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆