knitr icon indicating copy to clipboard operation
knitr copied to clipboard

Minor progress bar infelicity

Open hadley opened this issue 2 years ago • 6 comments

I am loving the new progress bar! But I noticed a couple of small issues exemplified by this simple Rmd:

```{r alpha}
Sys.sleep(0.5)
```

```{r bravo}
Sys.sleep(0.5)
```

```{r charlie}
Sys.sleep(5)
```

After alpha and bravo have completed and charlie is still running, I see this:

Screenshot 2023-02-08 at 13 00 06

Two small problems:

  • Weirdly, the processing message appears part way in the middle of the progress bar
  • The progress bar shows 100% complete even though we're still working on chunk 3.

By filing an issue to this repo, I promise that

  • [x] I have fully read the issue guide at https://yihui.org/issue/.
  • [x] I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • [x] I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

hadley avatar Feb 08 '23 19:02 hadley

Even more nitpicky, I noticed that if I run rmarkdown::render() there are two blank lines before the progress bar starts:

> rmarkdown::render("delay.Rmd")


processing file: delay.Rmd
  |........................                                                 |  33% (alpha)  

hadley avatar Feb 08 '23 22:02 hadley

And maybe there's one extra empty line at the bottom too? (at least when run_pandoc = FALSE).

> invisible(rmarkdown::render("delay.Rmd", run_pandoc = FALSE))

processing file: delay.Rmd
                                                                                                                 
output file: delay.knit.md

> 

hadley avatar Feb 08 '23 22:02 hadley

Hmmm, the first problem (where "processing..." is interleaved in the output") might actually be an RStudio problem

hadley avatar Feb 09 '23 15:02 hadley

It is an RStudio bug: https://github.com/rstudio/rstudio/issues/8160. knitr could work around it by outputing the "Process file" message to stdout() instead of stderr(). We have some techniques to do this in rlang/cli, but you could also just switch the message() to cat().

@kevinushey pointed me to this article on why interleaving streams is generally hard: https://unix.stackexchange.com/questions/476080/what-prevents-stdout-stderr-from-interleaving/476089#476089. You might also argue that maybe the problem is that the progress bar is using stdout() since everything that appears in this display will be using stderr()

hadley avatar Feb 09 '23 17:02 hadley

Not 100% sure this is the same problem, but note that in this connnect log the progress bar shows up after the error.

Screenshot 2023-02-13 at 16 03 18

hadley avatar Feb 13 '23 22:02 hadley

This is almost surely an RStudio issue -- not sure if there's a way to replicate the same flow in a "regular" R instance outside of RStudio.

kevinushey avatar Feb 13 '23 23:02 kevinushey