Skip to content
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

Extraneous positioning dataframe emitted when combining grobs in Rmarkdown notebooks #231

Closed
davidski opened this issue Jan 8, 2021 · 7 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@davidski
Copy link

davidski commented Jan 8, 2021

As always, thank you so much for the wonderful packages!

Under patchwork 1.1.1 (sessioninfo here: sessioninfo.txt), all the grob combination operations I can think of (+, /, wrap_plots(), etc). print the positioning frame when run in the context of a RMarkdown notebook. This dataframe is not output when run from the console.

The constructed patchwork object otherwise works as expected, so this is a display issue when generating notebooks rather than a critical functionality issue.

Issue has been replicated via the R4DS Slack community as well.

library(ggplot2)
library(patchwork)
gg1 <- ggplot(mtcars, aes(mpg, cyl)) + 
  geom_point()

gg2 <- ggplot(mtcars, aes(hp, disp)) + 
  geom_point()

foo <- gg1 + gg2 + plot_layout(ncol = 1)

Screen Shot 2021-01-08 at 11 26 45 AM

@davidski davidski changed the title Extraneous posiitoning dataframe emitted when combining grobs in Rmarkdown notebooks Extraneous positioning dataframe emitted when combining grobs in Rmarkdown notebooks Jan 8, 2021
@vadimus202
Copy link

vadimus202 commented Jan 19, 2021

I noticed the same issue after upgrading some tidyverse packages. The data frame only prints during assignment of combined plots to a variable.

@rspreafico
Copy link

Same here

@davidski
Copy link
Author

davidski commented Jun 6, 2021

@thomasp85 Any chance you could give a pointer on where to look to debug this issue? I'm happy to give a stab and identifying the root problem but am having a bit of uphill climb on understanding the flow of what's involved in this issue. Any debug guide you could give would be super appreciated. I'd love to get this issue fixed!

@thomasp85
Copy link
Owner

Hum... this looks super weird and I have no idea on top of my head for where the issue is

I'm sure I can fix this when I get around to it, but I'm afraid I wouldn't know how to guide others in the meantime

@davidski
Copy link
Author

davidski commented Aug 2, 2021

Very much appreciated! If there is any support we can give from a user side, please don't hesitate to ask. This particular issue is a personal bit of grit in my eye that I'd like to remove. 😄

@thomasp85 thomasp85 added the bug an unexpected problem or unintended behavior label Aug 8, 2023
@kevinushey
Copy link
Contributor

I've taken a look, and it looks like a bug in RStudio. To explain the behavior:

  1. When executing a Notebook chunk, RStudio inserts its own print() overrides, so that it can detect and capture attempts to print R objects. This is what allows RStudio to capture e.g. data.frame print-outs in a clean way.
  2. RStudio also tries to detect changes to objects in the Environment pane as code chunks are executed. When new objects are created, or changed, we try to introspect those new objects to learn a bit more about those objects.
  3. To that end, when inspecting the foo object, we call str(foo) -- but this involves calling print() when examining some of the internal data in foo.
  4. Unfortunately, because the print() overrides in (1) are still active, we end up inadvertently capturing that output into the Notebook chunk.

I think we can fix this on the RStudio side by making sure we deactivate our print overrides when updating the Environment pane.

@thomasp85
Copy link
Owner

Thanks @kevinushey — I'm going to close it here as there is nothing more to do on the patchwork side of things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

5 participants