Kian
Kian

Reputation: 3229

Why is this R output not getting redirected?

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?

Upvotes: 1

Views: 174

Answers (1)

Peyton
Peyton

Reputation: 7396

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 &

Upvotes: 5

Related Questions