I finally found this in the documentation of r_bg
:
#' @inheritParams r
Which indicates that the answer to my question is in the help file of the function callr::r
:
Error handling
callr handles errors properly. If the child process
throws an error, then callr throws an error with the same error
message in the main process.
The error expert argument may be used to specify a different behavior
on error. The following values are possible:
error is the default behavior: throw an error in the main process,
with a prefix and the same error message as in the subprocess.
stack also throws an error in the main process, but the error is of a
special kind, class callr_error, and it contains both the original
error object, and the call stack of the child, as written out by
utils::dump.frames(). This is now deprecated, because the error thrown
for "error" has the same information.
debugger is similar to stack, but in addition to returning the
complete call stack, it also start up a debugger in the child call
stack, via utils::debugger().
The default error behavior can be also set using the callr.error
option. This is useful to debug code that uses callr.
callr uses parent errors, to keep the stacks of the main process and
the subprocess(es) in the same error object.
In other words, the message can not be suppressed at the moment (as far as I can see), except with something hacky like this:
rp <- callr::r_bg(function() stop("You should see this"), error = "error")
Sys.sleep(2)
res <- tryCatch(rp$get_result(), error = function(e) {
# e <<- e
e$message <- "my package"
print(e)
})
#> <callr_error/rlib_error_3_0/rlib_error/error>
#> Error:
#> ! my package
#> Caused by error in `(function () …`:
#> ! You should see this
#> ---
#> Subprocess backtrace:
#> 1. base::stop("You should see this")
#> 2. | base::.handleSimpleError(function (e) …
#> 3. global h(simpleError(msg, call))