quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.93k stars 325 forks source link

Cannot use `base::sink(stdout(), type = "message")` within quarto document #9708

Closed jtlandis closed 5 months ago

jtlandis commented 5 months ago

Bug description

As the title describes, attempting base::sink(stdout(), type = "message") halts execution with no indication of why.

This seems to be only for the case when using stdout() and type = "message". A different file connection works with sink().

Steps to reproduce


```{r}
sink(stdout(), type = "message")
stop("This should print as stdout")
sink(NULL, type = "message")

### Expected behavior

I would expect the document to render with the output being written to the document. Or at least expect an error as to why this combination of arguments do not work.

### Actual behavior

In background jobs, we see it begin to render. The last step reported is `processing file: <name>.qmd` and it indicates it had failed.

### Your environment

- IDE: RStudio Version 2024.04.1+748 (2024.04.1+748)
- MacOS BigSur Version 11.7.4

### Quarto check output

```bash

Quarto 1.4.553
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.4.553
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (external install)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/jtlandis/Library/TinyTeX/bin/universal-darwin
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.11.7
      Path: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

[✓] Checking R installation...........OK
      Version: 4.4.0
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library
      knitr: 1.46
      rmarkdown: 2.26

[✓] Checking Knitr engine render......OK
mcanouil commented 5 months ago

Thanks for the report, unfortunately, that's not Quarto, it's knitr behaviour. I would suggest to open it on https://github.com/yihui/knitr/issues. (cc @cderv)

cderv commented 5 months ago

I would say this is even lower in the stack withing evaluate R package. It uses sink() internally so I guess there are some side effect of using evaluate::evaluate() on a call with another sink() .

Some weird behavior with this are reported already, so could be related:

So I would really look into R itself and evaluate package outside of the Quarto or R Markdown context.

You should open a discussion upstream - we'll close this here in the meantime.

Thanks.