Start RScript without DOS box (on Windows)?

落花浮王杯 提交于 2020-01-01 10:13:00

问题


For a tcltk application, I would like to start an R script without opening a console window or starting a DOS box. I already figured out that by creating a link to RScript.exe I can force the console window to start minimized, but I wonder if I can avoid the console window at all?


回答1:


You want to "run R in batch mode". It's quite straightforward; there are some instructions here.

EDIT: I don't see a console window; here are the steps I took.

1) I created a file named r.bat containing the line Rterm --vanilla and saved it in the R startup working directory (as given by Sys.getenv("USERPROFILE")).

2) I created a test R script, test.r, that would take several seconds to run (so I'd have chance to see any windows popping up.

n <- 1e3
for(i in 1:10)
{
  qr.solve(matrix(runif(n*n), nrow = n), seq_len(n)/(n+1))  
}

Obviously you can run any script that you like.

3) I opened a dos command prompt in the same dir as r.bat and typed R <test.r> test.txt.



来源:https://stackoverflow.com/questions/3332075/start-rscript-without-dos-box-on-windows

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