I have an R script that I call from an interactive bash shell (MacOS Catalina). This is one of a series of scripts that I call from the interactive shell, so I need to know if the initial script failed. It seems that no matter how the script fails (assert_that, stop, stopfinot, quit), R always returns an exit status of 0. How can I return a non-zero exist status from a failed R script?
Here is an example R script (fail.r).
#!/usr/bin/env Rscript
#library(assertthat)
message("Starting script")
#assert_that(FALSE)
#stop('Fail')
#stopifnot(FALSE)
q(save="no", status=10, runLast=FALSE)
message("Should not reach here")
And here is how I might call it from a bash prompt
src/poc/fail.r
echo $?
Regardless of the method I use to exit the R script $? always returns 0.
A couple other posts address this issue, but do not seem to apply to my situation (How to get an Rscript to return a status code in non-interactive bash mode) and (Make R exit with non-zero status code)