@@ -359,3 +359,38 @@ format.ggproto_method <- function(x, ...) {
359
359
360
360
# proto2 TODO: better way of getting formals for self$draw
361
361
ggproto_formals <- function (x ) formals(environment(x )$ f )
362
+
363
+ # ' Debug wrapper for ggproto methods
364
+ # '
365
+ # ' @param method A ggproto method or function to debug.
366
+ # ' @param debug One of the following:
367
+ # ' * `"once"` for invoking `debugonce()` (default).
368
+ # ' * `"always"` for invoking `debug()`.
369
+ # ' * `"never"` for invoking `undebug()`.
370
+ # ' @param ... Arguments passed to the function invoked by the `debug` argument.
371
+ # '
372
+ # ' @return `NULL`, this function is called for its side-effects.
373
+ # ' @noRd
374
+ # '
375
+ # ' @examples
376
+ # ' p <- ggplot(mpg, aes(displ, hwy)) +
377
+ # ' geom_point()
378
+ # '
379
+ # ' if (interactive()) {
380
+ # ' ggproto_debug(GeomPoint$draw_panel)
381
+ # ' }
382
+ # '
383
+ # ' p
384
+ ggproto_debug <- function (method , debug = c(" once" , " always" , " never" ), ... ) {
385
+ if (inherits(method , " ggproto_method" )) {
386
+ method <- environment(method )$ f
387
+ }
388
+ check_function(method )
389
+ switch (
390
+ arg_match0(debug , c(" once" , " always" , " never" )),
391
+ once = debugonce(method , ... ),
392
+ always = debug(method , ... ),
393
+ never = undebug(method , ... )
394
+ )
395
+ }
396
+
0 commit comments