Insufficient ggproto print methods??

Today in attempting to understand design principles:

In A Layered Grammar of Graphics we learn that a layer consists of 5 things:

- Data
- Mapping
- Geom
- Stat
- Position

When we create a ggproto object and print it, we are informed of 4/5 of the components of the layer: mapping, geom, stat, and position. When the data is also provided it would seem logical that the 5th component should be printed in the resultant object as well.

For example

geom_point(aes(Sepal.Length, Sepal.Width), data = iris)
#> mapping: x = ~Sepal.Length, y = ~Sepal.Width 
#> geom_point: na.rm = FALSE
#> stat_identity: na.rm = FALSE
#> position_identity

Created on 2020-03-03 by the reprex package (v0.3.0)

When data is provided to the object, they behave differently.


# define point layers 
w_data <- geom_point(aes(Sepal.Length, Sepal.Width), iris)
wo_data <- geom_point(aes(Sepal.Length, Sepal.Width))

ggplot() +

ggplot() +
#> Error in FUN(X[[i]], ...): object 'Sepal.Length' not found

Created on 2020-03-03 by the reprex package (v0.3.0)

My thinking is that when the data are or are not provided, that should be explicitly stated in the print method as it has very real consequences in the way that one can use the resultant object.

I'm not sure I understand what your question is here. Are you trying to implement an alternative S3 print method for ggproto objects, or is this a feature request for ggplot2 itself?

If the latter, you should probably file an issue in the ggplot2 GitHub repo.

If you haven't, I highly recommend reading the Extending ggplot2 vignette beforehand.

As Hadley describes, there are a lot of things he would do differently were he designing it today, but there are certain aspects that are nigh impossible to touch given the number and breadth of reverse dependencies.