Skip to content

Instantly share code, notes, and snippets.

@jonocarroll
Created November 6, 2022 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonocarroll/783f4b45b5e1e8f372c0409b54ddc4e9 to your computer and use it in GitHub Desktop.
Save jonocarroll/783f4b45b5e1e8f372c0409b54ddc4e9 to your computer and use it in GitHub Desktop.
Debug function for R based on Rust's dbg! macro
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