Since the tidyverse developer day is near, I share my very very secret technique to debug ggplot2. Though this is a very small thing, hope this helps someone a bit.
ggplot2 is unbreakable!
You might want to
debug() the methods of
But, this is not effective because the (edit: @BrodieGaslam told me I’m wrong. The reason we can’t do
geom_point() generates different instances, so their
draw_panel are all different objects (c.f. R6 classes have
debug method for this).
debug(GeomPoint$draw_panel) s because
$ is overridden and
debug(get("draw_panel", GeomPoint)) definitely works.)
Then what about RStudio’s nice breakpoint features?
Usually, this is enough. But, ggplot2’s
ggprotos are not the case. You cannot use breakpoints to dig into them.
Hmm… But, no, you don’t need to scratch your head. The solution is pretty simple.
You just need to
browser()on the line where you want to debug, and
- load all (
Ctrl+Shift+Lfor Windows, and
C-c C-w lfor Emacs/ESS).
Then, you’ll be on debug mode at last!
That’s all for this posts. But, I guess there are many alternative ways to achieve this, and I’m almost sure, at the end of the developer day, I will feel shame to have published this post, which just describes my debug skill is so poor… I’m really looking forward to learning from others. See you there!