Unserialization of wrap_plots loses plots
Steps to reproduce:
- 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")
- In a clean R session:
readRDS("test.rds")
# shows only p2
Is this expected behaviour?
Actually, the following shows both plots:
library(patchwork)
readRDS("test.rds")
which shouldn't be necessary.
why shouldn't it be necessary to have patchwork attached when displaying a patchwork plot?
Attaching ggplot2 is not needed, so I would expect the same for patchwork.
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