Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Open
loreabad6 opened this issue Jul 16, 2024 · 2 comments
Assignees
Labels
bug Something isn't working knitr third-party Issues involving interaction with a third-party library

Comments

@loreabad6
Copy link

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:

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

Now let's change the color:

```{r}
par(col="red")
```

And we plot again:

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

or

---
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:

```{r}
par(col="red")
```

And we plot again:

```{r}
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:
        - /usr/local/lib/R/site-library
        - /usr/local/lib/R/library
      knitr: 1.48
      rmarkdown: 2.27

[✓] Checking Knitr engine render......OK
@loreabad6 loreabad6 added the bug Something isn't working label Jul 16, 2024
@cderv
Copy link
Collaborator

cderv commented Jul 16, 2024

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.

@cderv cderv added third-party Issues involving interaction with a third-party library knitr labels Jul 16, 2024
@VadimSokolov
Copy link

This is expected behavior. It is there so you can modify the same plot across multiple code chunks. What you probably want is opts_knit$set(global.par = TRUE)

@cderv cderv self-assigned this May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working knitr third-party Issues involving interaction with a third-party library
Projects
None yet
Development

No branches or pull requests

3 participants