You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
utils::capture.output(expr) and therefore also R.utils::captureOutput(expr) assumes that the evaluated expression expr closes any sinks it opens. However, if this is not the case, then utils::capture.output() fails to properly close the sink it opened itself and therefore also fail to capture the output. For example,
Have captureOutput() detect when the sink stack is unbalanced before attempting to close the sink it has opened. This can be done by recording the depth <- sink.number(type = type)after initiating its sink and then making sure that currDepth <- sink.number(type = type) matches this sink depth before closing the sink again. If currDepth != depth, then there is an imbalance. What should happen in this case could be controlled by an new argument onUnbalance = c("ignore", "error", "warning"), where "ignore" is the current behavior.
If currDepth > depth, then captureOutput() could close the extra ones automatically before closing its own sink. This could be controlled by a new argument balance = FALSE. If TRUE, it'll close the extra sinks. If FALSE, the error message could include information on how many extra sinks are open.
If currDepth < depth, then there is nothing captureOutput() can do. However, it could still detect it and exit cleanly, e.g. making sure to close any raw/file connection it has opened and generate an informative error message explaining it could not recover.
The text was updated successfully, but these errors were encountered:
Issue
utils::capture.output(expr)
and therefore alsoR.utils::captureOutput(expr)
assumes that the evaluated expressionexpr
closes any sinks it opens. However, if this is not the case, thenutils::capture.output()
fails to properly close the sink it opened itself and therefore also fail to capture the output. For example,The above call corrupts R's sinks and their associated connections;
To fix this, we need to know how many sinks are still open and attempt to close them manually, e.g.
Suggestion
Have
captureOutput()
detect when the sink stack is unbalanced before attempting to close the sink it has opened. This can be done by recording thedepth <- sink.number(type = type)
after initiating its sink and then making sure thatcurrDepth <- sink.number(type = type)
matches this sink depth before closing the sink again. IfcurrDepth != depth
, then there is an imbalance. What should happen in this case could be controlled by an new argumentonUnbalance = c("ignore", "error", "warning")
, where"ignore"
is the current behavior.If
currDepth > depth
, thencaptureOutput()
could close the extra ones automatically before closing its own sink. This could be controlled by a new argumentbalance = FALSE
. IfTRUE
, it'll close the extra sinks. IfFALSE
, the error message could include information on how many extra sinks are open.If
currDepth < depth
, then there is nothingcaptureOutput()
can do. However, it could still detect it and exit cleanly, e.g. making sure to close any raw/file connection it has opened and generate an informative error message explaining it could not recover.The text was updated successfully, but these errors were encountered: