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

Feature request: implement ggplot_build.ggplot_built S3 method. #5800

Open
teunbrand opened this issue Mar 25, 2024 · 0 comments · May be fixed by #5803
Open

Feature request: implement ggplot_build.ggplot_built S3 method. #5800

teunbrand opened this issue Mar 25, 2024 · 0 comments · May be fixed by #5803

Comments

@teunbrand
Copy link
Collaborator

teunbrand commented Mar 25, 2024

Several getter functions, like layer_data(), call ggplot_build() on a plot.
For testing purposes, it might be more convenient to build a plot once and then extract relevant data/grobs/scales without having to build the plot every time.
Therefore, it can be convenient to have a ggplot_build.ggplot_built S3 method that just returns the input unaltered.
That way, it should be safe to use layer_data() or somesuch with a pre-build plot as input.

To express in code, I would like the following to work:

library(ggplot2)
p <- ggplot(mpg, aes(displ, hwy)) + geom_point()
build <- ggplot_build(p)

layer_data(build)
#> Error in UseMethod("ggplot_build"): no applicable method for 'ggplot_build' applied to an object of class "ggplot_built"
layer_grob(build)
#> Error in UseMethod("ggplot_build"): no applicable method for 'ggplot_build' applied to an object of class "ggplot_built"
layer_scales(build)
#> Error in UseMethod("ggplot_build"): no applicable method for 'ggplot_build' applied to an object of class "ggplot_built"

Created on 2024-03-25 with reprex v2.1.0

@teunbrand teunbrand changed the title Feature request: implement ggplot_build.ggplot_build S3 method. Feature request: implement ggplot_build.ggplot_built S3 method. Mar 25, 2024
@teunbrand teunbrand linked a pull request Mar 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant