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

Unserialization of wrap_plots loses plots #242

Closed
Enchufa2 opened this issue Apr 12, 2021 · 4 comments
Closed

Unserialization of wrap_plots loses plots #242

Enchufa2 opened this issue Apr 12, 2021 · 4 comments

Comments

@Enchufa2
Copy link

Steps to reproduce:

  1. Create a patchwork object and serialize it:
library(ggplot2)
library(patchwork)

p1 <- ggplot(iris) + aes(Sepal.Length) + geom_histogram()
p2 <- ggplot(iris) + aes(Sepal.Length, Sepal.Width) + geom_point()
wrap_plots(p1, p2)
# shows a composition of p1 and p2

saveRDS(last_plot(), "test.rds")
  1. In a clean R session:
readRDS("test.rds")
# shows only p2

Is this expected behaviour?

@Enchufa2 Enchufa2 changed the title Serialization of wrap_plots loses plots Unserialization of wrap_plots loses plots Apr 12, 2021
@Enchufa2
Copy link
Author

Actually, the following shows both plots:

library(patchwork)
readRDS("test.rds")

which shouldn't be necessary.

@thomasp85
Copy link
Owner

why shouldn't it be necessary to have patchwork attached when displaying a patchwork plot?

@Enchufa2
Copy link
Author

Enchufa2 commented Aug 4, 2023

Attaching ggplot2 is not needed, so I would expect the same for patchwork.

@thomasp85
Copy link
Owner

The reason why it works in ggplot2 is a weird side effect of ggplot objects including a reference to the ggplot2 namespace deep inside the scales list. It was quite surprising as method dispatch in R in general doesn't work without the package loaded

I can probably try to emulate it in patchwork to cheat the classic R mechanics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants