Last active
October 1, 2021 06:18
-
-
Save yjunechoe/96b25f220c0e8cb0e27ccf0141d1604d to your computer and use it in GitHub Desktop.
You can do this???
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| # This retrieves the function body | |
| body(get("compute_group", StatCount)) | |
| # This splits the execution sequence as a list | |
| as.list(body(get("compute_group", StatCount))) | |
| # The trace call | |
| trace( | |
| "compute_group", # the method to trace | |
| where = StatCount, # the ggproto object that the method belongs to | |
| at = 8, # the step to trace | |
| tracer = quote({ # the expression to evaluate at that step | |
| cat("> print(bars)\n") | |
| print(bars) | |
| }), | |
| exit = quote(untrace("compute_group", where = StatCount)) # called at the end to have a "traceonce" effect | |
| ) | |
| ggplot(mtcars, aes(cyl)) + geom_bar() | |
| # For even more power, `edit = TRUE` | |
| # trace("compute_group", where = StatCount, edit = TRUE) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Multiple tracer exprs at multiple execution steps !!!
If this ends up being wrapped in a function, needs to rm tracer_idx on exit