I'm trying to figure out how to use the error handling in the callr
package (which creates sub processes for R).
Here is a reprex:
rp <- callr::r_bg(function() stop("You should see this"), error = getOption("callr.error", "error"))
Sys.sleep(2)
rp$get_result()
#> Error: ! in callr subprocess.
#> Caused by error in `(function () …`:
#> ! You should see this
Created on 2023-07-11 with reprex v2.0.2
What I want to accomplish is to suppress the messages #> Error: ! in callr subprocess. #> Caused by error in (function () …:
and only show Error: You should see this
. The background is that this will go into a function and I think it will confuse users to see the callr reference.
It seems that the error argument could be used to accomplish that. The documentation reads:
error: What to do if the remote process throws an error. See details below.
But I can't find these details and don't know what options might be valid here.
I finally found this in the documentation of
r_bg
:Which indicates that the answer to my question is in the help file of the function
callr::r
:In other words, the message can not be suppressed at the moment (as far as I can see), except with something hacky like this: