5

When running

R CMD BATCH [options] filename.r

I want to control where the output is printed. I can suppress the creation of the .Rout file with

R CMD BATCH [options] filename.r /dev/null

but is it possible to direct the output to the screen? Like when I run it by

R [options] < filename.r

?

hatmatrix
  • 42,883
  • 45
  • 137
  • 231

3 Answers3

4

Guess you're on linux. Tried already to redirect to /dev/console ?

Edit -add info from the comments -:

/dev/console apparently doesn't work, /dev/tty does. Depending on the system, /dev/tty0 might be an option too

Cheers

Joris Meys
  • 106,551
  • 31
  • 221
  • 263
3

Try Rscript or R --no-save < filename.R:

biocoreap1:Desktop vinceb$ Rscript test.R
test
biocoreap1:Desktop vinceb$ R --no-save < test.R

R version 2.10.1 (2009-12-14)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

[...]

[Previously saved workspace restored]

> cat('test\n')
test
> 
Vince
  • 7,608
  • 3
  • 41
  • 46
  • Thanks - that's the way I've been doing it (using input redirection), but want to emulate its behavior (the part where it prints to screen) with the R CMD BATCH - David Smith [notes][1] that there are advantages to R CMD BATCH, and I also use emacs eshell which does not support input redirection. And I know about Rscript also, but that requires that I add a line to the header and the make it executable, etc. [1] http://blog.revolutionanalytics.com/2009/06/running-scripts-with-r-cmd-batch.html – hatmatrix Aug 28 '10 at 23:38
  • There is no shebang in the Rscript script I tested above: It's just `cat('test\n')`. You only need executable + shebang if you want to run it with `./filename.R`, not `Rscript filename.R` – Vince Aug 28 '10 at 23:50
  • Ah! That's nice - but there's nothing printed to screen except through explicit calls to cat() or print() or write*()? I am hoping for what's printed to screen in `R --no-save < test.R`, or the comments printed to file in the R CMD BATCH case... – hatmatrix Aug 29 '10 at 00:16
  • You see when you have an error with `Rscript`. Try something like `lm('BUG`)`. – Vince Aug 29 '10 at 03:12
  • Hmm... yes, I see... doesn't always indicate where the error was (in a long script with similar statement calls), as does printing the input and output to screen. Maybe this is the best way though? – hatmatrix Aug 30 '10 at 12:36
  • @Vince - thanks - I will keep Rscript in mind, but this time it was the output that directing to /dev/tty provides that I was looking for. But thanks though! – hatmatrix Aug 30 '10 at 23:17
1

You can maybe do both at the same time (creating the file and printing on screen) if you run R CMD BATCH [options] filename.r and then tail -f filename.Rout

Jean-Robert
  • 840
  • 6
  • 10