Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WISH: Make it possible to stack stderr (aka "message") sinks #55

Open
HenrikBengtsson opened this issue Feb 14, 2018 · 2 comments
Open
Labels
annoyance enhancement help wanted on r-devel or r-pkg-devel mailing lists Issue has been raised on the R-devel or R-pkg-devel mailing lists

Comments

@HenrikBengtsson
Copy link
Owner

HenrikBengtsson commented Feb 14, 2018

Issue

In ?sink we can read:

Sink-ing the messages stream should be done only with great care. For that stream file must be an already open connection, and there is no stack of connections.

This prevents us from doing things such as:

> x <- capture.output({
+   message(1)  ## this is captured, but ...
+   y <- capture.output(message(2), type="message")
+   message(3)  ## ... these two message/stderr output
+   message(y)  ## messages are _not_ captured
+ }, type="message")
3
2
> x
[1] "1"

The latter two lines are outputted to the message output, which reopened, because the inner capture resets it to the default when it closes it's redirect.

This is a problem, because it prevents all of us from capturing/sinking standard error output ("messages"). If we attempt to do it, we must be careful to make sure there is not already an active "message" sink, otherwise we will destroy the active one. This makes it very complicated to capture stderr in package code. This is basically also what ?sink tells us:

Do not sink the messages stream unless you understand the source code implementing it and hence the pitfalls.

Actions

Try to find out why the current limitation exists. Is it deliberate - an active design decision - and if so, then exactly why? Or is it just because no one got around to implement a stacked version for the "message" streams?

@HenrikBengtsson
Copy link
Owner Author

Asked about this in R-devel thread 'sink(con, type = "message"): what is the reason why 'message' sinks cannot be stacked?', 2018-03-20 (https://stat.ethz.ch/pipermail/r-devel/2018-March/075734.html)

@HenrikBengtsson HenrikBengtsson added the on r-devel or r-pkg-devel mailing lists Issue has been raised on the R-devel or R-pkg-devel mailing lists label Aug 29, 2018
HenrikBengtsson added a commit to HenrikBengtsson/future.tests that referenced this issue Jan 21, 2019
@HenrikBengtsson HenrikBengtsson changed the title WISH: Make it possible to stack "message" sinks WISH: Make it possible to stack stderr (aka "message") sinks Feb 15, 2019
@HenrikBengtsson
Copy link
Owner Author

See R-devel thread 'Bug report: parLapply with capture.output(type="message") produces an error' on 2023-10-05 (https://stat.ethz.ch/pipermail/r-devel/2023-October/082936.html) for an example where the lack of stackable "message" sinks is in play.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annoyance enhancement help wanted on r-devel or r-pkg-devel mailing lists Issue has been raised on the R-devel or R-pkg-devel mailing lists
Projects
None yet
Development

No branches or pull requests

1 participant