quarto-dev / quarto-dev/quarto-cli

Bug: Quarto render with intermediate print statements results in split code blocks for html and lost content for ipynb

Open
#12,497 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug engines-knitr ipynb-format
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

Bug description

A code block with intermediate print statements appears to be splitting the code block into two when rendering html (minor bug) and truncating the code block at the print when rendering ipynb (major bug).

Steps to reproduce

Considering the following qmd file, where the only difference in behavior is if the print("getting all analyses") is kept or commented out.

---
title: Test Notebook
format:
  html:
    embed-resources: true
  ipynb:
    default
---

```{r login}
# Stub to get analysis
get_analysis <- function() {
    print("getting all analyses") # this line is commented out for notebook_no_print results
    analysis <- list(
        list(analysis_name = "AvsB", id = 2),
        list(analysis_name = "CvsD", id = 3)
    )
    analysis
}

# Get analysis
analysis <- get_analysis()

# Filter Analysis
analysis <- purrr::keep(
    analysis,
    \(it) it$analysis_name == "AvsB"
)[[1]] |> as.list()

analysis
```

quarto render notebook_print.qmd and quarto notebook_no_print.qmd create the two bug states. Since I am unable to attach the html and ipynb, I will paste screenshots below.

notebook_no_print

html

Image

ipynb

Image

notebook_print

html

Code blocks are split
Image

ipynb

Code block is truncated
Image

Actual behavior

Code blocks with print in the middle split the code block in html (and truncate for ipynb). Other formats may also be impacted.

Expected behavior

I think in both cases the code blocks shouldn't be split (and certainly not truncated).

I think the correct behavior would be for the notebook_print case to behave like notebook_no_print case where all output being rendered after the code block. This also ensures the behavior similar to jupyter and also keeps code blocks together.

FWIW, this doesn't seem to be an issue when using {python}. The output looks as expected and the notebook is fine as well:

Image

Your environment
  • Shell: zsh 5.9 (arm64-apple-darwin24.0)
  • OS: MacOS Sequoia 15.4
Quarto check output
Quarto 1.6.42
[✓] Checking environment information...
      Quarto cache location: /Users/hguturu/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.6.42
      Path: /Applications/quarto/bin

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

[✓] Checking LaTeX....................OK
      Tex:  (not detected)

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

[✓] Checking Python 3 installation....OK
      Version: 3.11.11
      Path: /Users/hguturu/git/pas-ai-notebooks-internal/.venv/bin/python3
      Jupyter: 5.7.2
      Kernels: python3, ir

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.4.3
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
      knitr: 1.50
      rmarkdown: 2.29

[✓] Checking Knitr engine render......OK

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with notebook_print.qmd and notebook_no_print.qmd using quarto render, comparing the R/knitr HTML and ipynb outputs. Trace the rendering path for intermediate print output and verify that both formats preserve one complete code block and all subsequent content, matching the Python behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, r
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.