Print during debugonce on RStudio Server doesn't work

I'm trying to debug an issue on RStudio Server. I used debugonce(my_function). The interface seems to be working as normal, however, the print function appears broken:

I say "working as normal" because if I simply pipe the output outside of R, it works:

R> capture.output(print(params), file = 'params.out')
bash> cat params.out
list()

Of course, this is much more inconvenient (especially since system calls within R are affected by the same malfunction, so I have to switch to the Terminal tab).

It's possible that R is sinking the output somewhere. You can check for active sinks with:

sink.number()

If that reports one or more sinks, you can try closing them with:

sink(NULL)
2 Likes

I'm not able to reproduce just now, but that sounds reasonable. Will circle back if the problem comes back. I certainly didn't tell R to sink anywhere, so it'd be worth considering where such a sink would have cropped up

Finally got this to reproduce (and locally - so RStudio Server seems not to be the root). sink(NULL) indeed fixed the issue, the only caveat is that of course running sink.number() requires print to be working as expected in the first place. So you'll have to capture.output(print(sink.number()), file = 'check_sink') to test this approach in full.

1 Like