Created
November 6, 2022 05:45
-
-
Save jonocarroll/783f4b45b5e1e8f372c0409b54ddc4e9 to your computer and use it in GitHub Desktop.
Debug function for R based on Rust's dbg! macro
This file contains 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
dbg <- function(x) { | |
ex <- rlang::f_text(rlang::enquos(x)[[1]]) | |
ret <- rlang::eval_bare(x) | |
message(glue::glue("DEBUG: {ex} = {ret}")) | |
ret | |
} | |
a <- 1 | |
b <- 3 | |
x <- dbg(a + b) | |
#> DEBUG: a + b = 4 | |
y <- dbg(2*x + 3) | |
#> DEBUG: 2 * x + 3 = 11 | |
z <- 10 + dbg(y*2) | |
#> DEBUG: y * 2 = 22 | |
z | |
#> [1] 32 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment