title: "where do file outputs go"
output: github_document
knitr::opts_chunk$set(echo = TRUE)
I created this file message_warning.R
#!/usr/bin/env Rscript
print("this is a print \n")
cat("this is a cat \n")
message("this is a message \n")
warning("this is a warning")
stop("this is a stop, or error!")
If you execute this file with Rscript
Rscript message_warning.R
You get this
[1] "this is a print \n"
this is a cat
this is a message
Warning message:
this is a warning
Error: this is a stop, or error!
Execution halted
However, if you pipe the output into a file you only get the stout
Rscript message_warning.R > stuff.txt
The shell returns
this is a message
Warning message:
this is a warning
Error: this is a stop, or error!
Execution halted
and stuff.txt contains
[1] "this is a print \n"
this is a cat
So standard print and cat are captured but message and warning are not.
But we can also write the sterr to file.
Rscript messgae_warning.R 2> stuff.txt
Now the shell outputs
[1] "this is a print \n"
this is a cat
and the stuff.txt file contains
this is a message
Warning message:
this is a warning
Error: this is a stop, or error!
Execution halted
title: "where do file outputs go" output: github_document
I created this file
message_warning.R
If you execute this file with Rscript
Rscript message_warning.R
You get thisHowever, if you pipe the output into a file you only get the stout
The shell returns
and stuff.txt contains
But we can also write the sterr to file.
Now the shell outputs
and the stuff.txt file contains
How do you get them both?