However, that paragraph doesn't give a lot of guidance about when to use Class$method() and when to use ggproto_parent(Class, self)$method(). I think it would help if it was clearer that the Class$method() approach is safe when no reading or writing to/from self happens (i.e. the Class$method() formals doesn't include self), and less safe otherwise. To give an example a difference occurs:
In chapter 19.4.5 the following is said about using the
ggproto_parent()
function:https://github.com/hadley/ggplot2-book/blob/ff77ea98501a4edbd9c5a95344d4f80140105f7f/internals.qmd#L564
However, that paragraph doesn't give a lot of guidance about when to use
Class$method()
and when to useggproto_parent(Class, self)$method()
. I think it would help if it was clearer that theClass$method()
approach is safe when no reading or writing to/fromself
happens (i.e. theClass$method()
formals doesn't includeself
), and less safe otherwise. To give an example a difference occurs:Created on 2023-07-19 with reprex v2.0.2
In the example
Coffee$describe()
would of course give the correct answer, but that is besides the point.