r-lib / callr

Call R from R
https://callr.r-lib.org/
Other
297 stars 36 forks source link

How to detect failure in `r_bg()` ? #270

Closed krlmlr closed 8 months ago

krlmlr commented 8 months ago

get_exit_status() doesn't seem to be useful:

p <- callr::r_bg(function() stop(), error = "error")
p$wait()
p$get_exit_status()
#> [1] 0
writeLines(p$read_all_error_lines())
#> Error in (function ()  :

Created on 2024-01-18 with reprex v2.0.2

gaborcsardi commented 8 months ago

Call p$get_result() and it'll throw a callr_status_error if there was an error in the subprocess.