43

Unlike the similar command R CMD BATCH which by default produces an output file which contains any error messages which would cause the execution of a script to halt, I have not been able to find a way to do this with Rscript. I have tried using a pipe in my linux shell to achieve this:

RScript --no-save --no-restore --verbose myRfile.R > outputFile.Rout

but this will only pipe over any output that occurred before an error occurs, so the file outputFile.R doesn't contain any error information. Does anyone know how to get the capture any errors that occur in executing an R file using RScript and saving it to a file?

0

1 Answer 1

63
Rscript --no-save --no-restore --verbose myRfile.R > outputFile.Rout 2> errorFile.Rout

To put the output and error in the same file (assuming sh/bash)

Rscript --no-save --no-restore --verbose myRfile.R > outputFile.Rout 2>&1
Sign up to request clarification or add additional context in comments.

5 Comments

Amazing. But could you educate me. What's the 2> syntax mean?
2> means redirect standard error (file descriptor number 2).
what if I woould like to APPEND to a file that already exists?
Appending to an existing file can be done using >> instead of >: Rscript --no-save --no-restore --verbose myRfile.R >> outputFile.Rout 2>&1
In the R outfile, I got --no-echo --no-restore --no-save --no-restore --file even when I used the commands as given in the answer. What does --no-echo mean .. do not print?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.