Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: How to enable printing to console when using `future::plan(sequential)` when in `browser()`?

Tags:

r

future

The future package is great, but when debuging with future::plan(sequential), any print doesn't get printed to console.

I think there is an option to enable printing to console.

Hope posting will make it more googlable in the future.

like image 812
xiaodai Avatar asked Nov 06 '25 13:11

xiaodai


2 Answers

(Author of future here:) In future (>= 1.20.1) [2020-11-03], the official recommended solution is to use:

plan(sequential, split = TRUE)

This works with browser() and friends.

like image 76
HenrikB Avatar answered Nov 09 '25 03:11

HenrikB


The answer by xiaodai is the best and most robust. I log a separate workaround here that might be useful to some users when editing the arguments to the underlying future.apply() call is not convenient (e.g., the call is in a package).

After the browser() is called, you can enter sink() at the prompt. Output now goes to the terminal. The main caveat to this is that when future.apply attempts to close the sink() connection, there will be a warning because the connection has already been closed:

Warning in base::sink(type = "output", split = FALSE) :
  no sink to remove

This is especially annoying if you have the good habit of setting options(warn = 2). To temporarily work around this, you might consider temporarily setting options(warn = 0).

like image 35
scottkosty Avatar answered Nov 09 '25 01:11

scottkosty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!