patchwork icon indicating copy to clipboard operation
patchwork copied to clipboard

Cannot turn off printing of TLBR table in R Markdown or Quarto documents when composing plots with `wrap_plots` or `+`

Open caparks2 opened this issue 2 years ago • 3 comments

When composing plots using wrap_plots() or plot arithmetic operators in an R Markdown or Quarto document, and assigning the resulting patchwork to an object using <-, a table with columns "t", "l", "b", and "r" is printed in line as an output of the chunk. This cannot be avoided using invisible(). In an R Markdown document using knitr chunk options {r, results='hide'} fails to prevent the table from being printed while {r, include=FALSE} succeeds. In a Quarto document the execution option #| output: false fails while #| include: false succeeds.

R Markdown

image

Quarto

image

caparks2 avatar Sep 06 '23 19:09 caparks2

This is an issue in knitr - I'm in talk with the devs

thomasp85 avatar Oct 30 '23 08:10 thomasp85

@cderv looping you in so you have an eye on it

thomasp85 avatar Oct 30 '23 09:10 thomasp85

Hi.

This is the document[^1] I used to test

---
title: "test"
output: 
  html_document:
    keep_md: true
---

```{r}
library(ggplot2)
library(patchwork)
```

```{r}
p1 <- pressure |> 
  ggplot(aes(temperature, pressure)) + 
  geom_point()
```

```{r}
p1
```


```{r}
p2 <- p1 + 
  geom_smooth(
    method = 'lm',
    formula = y ~ poly(x, 5),
    se = FALSE
  )
```

```{r}
p2
```


```{r}
patch <- p1 + p2
```

```{r}
patch
```
  • Rendering this document using rmarkdown::render() will not show a table output for the patch chunk image

  • However, showing interactive chunk result inline will reproduce what you are seeing. This mean by adding the config to the document

    ditor_options: 
     chunk_output_type: inline
    

So I would say this is an RSTUDIO IDE issue that seems to print the patch <- p1 + p2 somehow. RStudio IDE has its printing method for the chunk interactive rendering and they do not live in rmarkdown or knitr.

This is tracked already at

  • https://github.com/rstudio/rstudio/issues/13470

Hope it helps


[^1]: please next time share a code we can copy paste or download instead of screenshot as this is easier for us. thanks

cderv avatar Oct 30 '23 09:10 cderv