Exporting .csv from R & Batch file

自古美人都是妖i 提交于 2020-01-05 10:07:31

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/17022957/exporting-csv-from-r-batch-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!