-
Notifications
You must be signed in to change notification settings - Fork 2k
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
could not find function
: Plot saved under old version of ggplot2 cannot be rendered with new version
#5865
Comments
Thanks for the report! We explicitly do not recommend saving ggplot objects to disk. While we do our best to keep the user-facing functions as stable as we reasonably can, no such promises are made about internal code. It would make ggplot2 unmaintainable if internal code has to be backward compatible with previous versions. Therefore, we recommend against saving plot objects to disk. As such, we won't fix rendering old plots with new versions. There are several things you might try for this issue:
|
Thank you @teunbrand for the Grob tip! I quickly tested it out and it seemed to work saving Grob to RDS from v3.4.4 and drawing it in v3.5.0. R with ggplot2 version 3.4.4: ggplotGrob(gg_fig) -> gg_grob
saveRDS(gg_grob, file="gg_grob_3_4_4.rds") R with ggplot2 version 3.5.0: readRDS("gg_grob_3_4_4.rds") -> gg_grob_old_ver
grid::grid.draw(gg_grob_old_ver) Works the other way round, too. Save the Grob object from v3.5.0 and grid.draw it in v3.4.4. |
Just for discoverability - the same issue (obviously) arises when the Rmd cache=TRUE option is used. |
Commenting here in case others have had the I bumped into this error because I am using |
I'll change the title for better discoverability |
could not find function
: Plot saved under old version of ggplot2 cannot be rendered with new version
Short background: I make quite extensive reports using RMarkdown and they often include figures produced with ggplot2. For faster re-knitting, I like to save finished tables and figures to RDS files and just use readRDS() function in the knit phase.
Few days ago I had to get back to an old project and add a new table to the report but suddenly the file refused to knit and threw an error.
Here is the code to reproduce the bug:
Fresh R session with ggplot2 version 3.4.4:
Fresh R session with ggplot2 version 3.5.0:
This produces 'could not find function "scales_add_defaults"' error:
It took me quite a while to figure out what's causing the error because nothing changed in the report except the newly added table.
I drew the figure with both versions and compared the ggplot-object names:
I think the newer version of ggplot2 cannot render a figure that has been made with version 3.4.4 because version 3.4.4 ggplot-object doesn't have guides- and layout- ggproto-objects in it?
The text was updated successfully, but these errors were encountered: