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
.