tags:

views:

135

answers:

1

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?

+3  A: 

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.

Richie Cotton
Thank you for the link, however it seems that Rterm.exe opens a console window, too. But I think I can live with a minimized start of the session, which is also useful for reading the output messages.
Karsten W.
The thing is, I don't want to see the windows popping up you describe in step 2, only if I explicitly create (via tcltk) a window, and I don't want to start a DOS box first. I edited the question accordingly.
Karsten W.
@Karsten: I believe you can run DOS commands without creating a window by putting the commands into a batch file (`.bat`) that has the first line `@echo off`.
Richie Cotton