Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions R/ggproto.R
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,38 @@ format.ggproto_method <- function(x, ...) {

# proto2 TODO: better way of getting formals for self$draw
ggproto_formals <- function(x) formals(environment(x)$f)

#' Debug wrapper for ggproto methods
#'
#' @param method A ggproto method or function to debug.
#' @param debug One of the following:
#' * `"once"` for invoking `debugonce()` (default).
#' * `"always"` for invoking `debug()`.
#' * `"never"` for invoking `undebug()`.
#' @param ... Arguments passed to the function invoked by the `debug` argument.
#'
#' @return `NULL`, this function is called for its side-effects.
#' @noRd
#'
#' @examples
#' p <- ggplot(mpg, aes(displ, hwy)) +
#' geom_point()
#'
#' if (interactive()) {
#' ggproto_debug(GeomPoint$draw_panel)
#' }
#'
#' p
ggproto_debug <- function(method, debug = c("once", "always", "never"), ...) {
if (inherits(method, "ggproto_method")) {
method <- environment(method)$f
}
check_function(method)
switch(
arg_match0(debug, c("once", "always", "never")),
once = debugonce(method, ...),
always = debug(method, ...),
never = undebug(method, ...)
)
}