Closed xiaodaigh closed 5 years ago
The underlying reason is that browser()
outputs to the standard output (stdout)(*) and futures capture stdout (to be relayed when their values are collected) by default. You can tell the future framework to leave the stdout "as is" by specifying future.stdout = NA
, e.g.
> library(future.apply)
> y <- future_lapply(1:2, function(x) { browser() }, future.stdout = NA)
Called from: ...future.FUN(...future.X_jj, ...)
Browse[1]> ls()
[1] "x"
Browse[1]> c
Called from: ...future.FUN(...future.X_jj, ...)
Browse[1]> c
>
(*) By my book, ideally browser()
would output to standard error (stderr), which is not captured. Second best would be if one could control this via an argument, e.g. browser(output = "stderr")
.
For the record, I've added this to the Wishlist-for-R.
I'll assume this resolved the problem for you, so I'm closing. If not, please reopen.
Just a follow-up here: One can use plan(sequential, split = TRUE)
; it's more convenient, and it avoids having to specify future.stdout = NA
. For example,
> library(future.apply)
> plan(sequential, split = TRUE)
> y <- future_lapply(1:2, function(x) { browser() })
Called from: ...future.FUN(...future.X_jj, ...)
Browse[1]> ls()
[1] "x"
Browse[1]> c
Called from: ...future.FUN(...future.X_jj, ...)
Browse[1]> c
Called from: ...future.FUN(...future.X_jj, ...)
[1] "x"
Called from: ...future.FUN(...future.X_jj, ...)
>
when browser is activated, I type
x
into the console, but it doesn't show up. Is there a way to let me inspect content whilst inside afuture_lapply
call?