Disclaimer This sounds like an XY problem, printing a stop message in stdout is of little importance, if interactive it shouldn't be a problem, if the script just uses the usual 2 > &1
redirection to write stderr messages to stdout or use sink
as in the answer to this question .
Now, if I correctly understood what you are after, I will do something like the following to avoid too much code refactoring.
First, define a function to handle errors:
my_stop <- function() { e <- geterrmessage() print(e) }
Now configure the system to send errors to your function (error handler) and suppress the error messages:
options(error = my_stop) options(show.error.messages=FALSE)
Now let's test it:
f1 <- function() { f2() print("This should not be seen") } f2 <- function() { stop("This is a child error message") }
Output:
> f1() [1] "Error in f2() : This is a child error message\n"
source share