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

progress: Output to stderr - not stdout #359

Closed
HenrikBengtsson opened this Issue Apr 11, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@HenrikBengtsson

HenrikBengtsson commented Apr 11, 2016

Issue

Download progress such as:

Downloading: 1.2 kB

is outputted to standard output (stdout). This means for instance that the progress is captured by report generators. Outputting to standard error (stderr) avoids this.

Troubleshooting

This is because cat() and utils::txtProgressBar() are called with defaults, which results in output to stdout. Passing file=stderr() to these functions would probably be enough.

Related code issues: Issue #344

@hadley hadley closed this in 222e8b2 May 20, 2016

@hadley

This comment has been minimized.

Member

hadley commented May 20, 2016

I made it an option - I couldn't change the default because it breaks the default progress behaviour (each update gets a new line when using stderr)

@HenrikBengtsson

This comment has been minimized.

HenrikBengtsson commented May 20, 2016

Thanks.

Could you clarify what you mean by "each update gets a new line when using stderr"? Why would stdout() and stderr() differ in what (character sequence) is outputted (other than to where)? You're not referring to behavior of message() here, which shouldn't be involved, correct?

@hadley

This comment has been minimized.

Member

hadley commented May 20, 2016

Just try it out yourself - stderr() doesn't seem to respond to "\r" in the same way as stdout() (at least in RStudio)

@HenrikBengtsson

This comment has been minimized.

HenrikBengtsson commented May 20, 2016

I see. It seems to come down to how RStudio handles \r (CR) in the two cases. Here's what I found using RStudio 0.99.902 (on Windows):

## Ask expected
> cat("abc\rABC\n", file=stdout())
ABC
> cat("abc\rABC\n", file=stderr())
ABC

## Different behavior between stdout and stderr
> cat("abc", file=stdout()); cat("\rABC\n", file=stdout())
ABC
> cat("abc", file=stderr()); cat("\rABC\n", file=stderr())
abcABC

## Also, it seems as '\r' is "forgotten" between cat() regardless of output
> cat("abc\r", file=stdout()); cat("ABC\n", file=stdout())
abcABC
> cat("abc\r", file=stderr()); cat("ABC\n", file=stderr())
abcABC

I've tried this on Windows (Rterm and Rgui) as well as Linux and I cannot reproduce this there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment