ggplot2
ggplot2 copied to clipboard
POC: Boilerplate functions
This PR aims to (eventually) fix #6142.
Briefly, it introduces boilerplate() that can take in a ggproto class and spit out a constructor.
This PR is a proof-of-concept because it probably merits some discussion whether we would like to go down this road. As such, the PR only implements boilerplate() for Geoms, but can be expanded in the future for Stats and Scales as well, I think.
The boilerplate() function is used for amenable functions, but not more complex ones. For example, geom_text() or geom_boxplot() perform input checking that we cannot currently easily fit into the boilerplate code.
A few notes about the PR:
- Because we apply this function for suitable geoms, we had to swap the position of class definition and constructor, as
boilerplate()takes the class as input. These are the largest diffs. - Some order of arguments are changed, as they are now handled consistently.
- Many geoms had 'hidden' parameters, i.e. parameters like
lineendthat would be accepted by theGeom$draw_panel/group()method, but were set as arguments to the constructor. These are now all exposed. - In visual tests, I had to accept the changes because
draw_key_polygon()now actually gets the line settings (lineend, linejoin, linemitre) from the geom instead of having to default these. - I don't have a lot of experience of programatically constructing function bodies. If there is a better way, I'd gladly accept pointers.