quarto-dev / quarto-cli

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

Setting knitr::opts_knit$set(global.device = TRUE) duplicates plots when rendering #10302

Open loreabad6 opened 1 month ago

loreabad6 commented 1 month ago

Bug description

Setting the knitr option for global device to true results in an unexpected behavior where the initial plot is displayed after each code chunk.

image

Steps to reproduce

---
title: "test"
format: html
embed-resources: true
---

```{r}
knitr::opts_knit$set(global.device = TRUE)

First a plot with default parameters:

plot(1:10)

Now let's change the color:

par(col="red")

And we plot again:

plot(1:10)

or 

````qmd
---
title: "test"
format: html
knitr:
  opts_knit:
    global.device: true
embed-resources: true
---

First a plot with default parameters:

```{r}
plot(1:10)

Now let's change the color:

par(col="red")

And we plot again:

plot(1:10)

### Expected behavior

Resulting plots from code chunk render once after their respective chunk.

### Actual behavior

Initial plot gets rendered after each code chunk.

### Your environment

- IDE: RStudio 2024.04.2
- OS: Linux Ubuntu 22.04.4 LTS

### Quarto check output

Quarto 1.4.555 [✓] 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.555 Path: /usr/lib/rstudio-server/bin/quarto/bin

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

[✓] Checking LaTeX....................OK Using: Installation From Path Path: /usr/local/texlive/bin/linux Version: 2024

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

[✓] Checking Python 3 installation....OK Version: 3.10.12 Path: /usr/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.1 Path: /usr/local/lib/R LibPaths:

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

cderv commented 1 month ago

This is not Quarto specific. More a knitr behavior . Using knitr::knit() on the file gives 4 plots in the .md document.

I need to look into this as I don't remember the impact of this options.