thomasp85 / patchwork

The Composer of ggplots
https://patchwork.data-imaginist.com
Other
2.42k stars 157 forks source link

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

Open caparks2 opened 10 months ago

caparks2 commented 10 months ago

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

thomasp85 commented 8 months ago

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

thomasp85 commented 8 months ago

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

cderv commented 8 months ago

Hi.

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

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

```{r}
library(ggplot2)
library(patchwork)
p1 <- pressure |> 
  ggplot(aes(temperature, pressure)) + 
  geom_point()
p1
p2 <- p1 + 
  geom_smooth(
    method = 'lm',
    formula = y ~ poly(x, 5),
    se = FALSE
  )
p2
patch <- p1 + p2
patch

* Rendering this document using `rmarkdown::render()` will not show a table output for the patch chunk 
   ![image](https://github.com/thomasp85/patchwork/assets/6791940/4cfbb3cc-64d5-479d-88b0-563b05fa9a92)

* However, showing interactive chunk result inline will reproduce what you are seeing. This mean by adding the config to the document
    ````yaml
    editor_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

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