1

I am using Ubuntu 14.04. I like to run R scripts from the terminal (bash) using the command Rscript. I like to redirect my output to a file, for example:

Rscript some_R_code.R > output.log &

(I like to run it in the background, which is why I use &).

And, indeed, 99% of the output does go to that file. But I do get the odd little messages which do not. For example:

Warning message:
replacing previous import ‘getCall’ when loading ‘fBasics’ 

is outputted to the terminal, when I want it to the file.

What is causing this, and how do I fix it?

Kian
  • 3,189
  • 3
  • 18
  • 16
  • 1
    You're only redirecting STDOUT. The warning message is being sent to STDERR. How you redirect STDERR that varies by shell (for bash see [here](http://stackoverflow.com/questions/818255/in-the-shell-what-is-21/818284#818284). Or, in R, you could redirect STDERR to STDOUT via [sink()](http://stackoverflow.com/questions/4112896/how-can-i-redirect-r-warning-messages-to-stdout) – MrFlick Oct 29 '14 at 18:53

1 Answers1

5

You direct stdout to a file, but warnings actually go to stderr. You can redirect both stderr and stdout using &>:

Rscript some_R_code.R &> output.log &

Or you could redirect stderr to a separate file:

Rscript some_R_code.R > output.log 2> err.log &
Peyton
  • 7,266
  • 2
  • 29
  • 29