Last active
April 8, 2022 10:45
-
-
Save moodymudskipper/3d3a89912c169fa6548957b2045d3f5e to your computer and use it in GitHub Desktop.
pipe_diff
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
pipe_diff <- function() { | |
pipe <- function (lhs, rhs) { | |
on.exit({ | |
extra <- | |
if(tibble::is_tibble(lhs) && tibble::is_tibble(res)) | |
list(n=Inf, width = Inf) else list() | |
previous <- lhs | |
added_nm <- deparse(expr)[[1]] | |
assign(added_nm, res) | |
diff_obj_expr <- substitute( | |
diffobj::diffPrint(previous, added, mode = "sidebyside", extra = extra), | |
list(added = as.symbol(added_nm)) | |
) | |
print(eval(diff_obj_expr)) | |
suppressWarnings(rm(list = "%>%", envir = parent.frame())) | |
}) | |
expr <- substitute(rhs) | |
if (is.symbol(expr) || expr[[1]] == quote(`(`)) { | |
expr <- as.call(c(expr, quote(.))) | |
} | |
else if (length(expr) == 1) { | |
expr <- as.call(c(expr[[1]], quote(.))) | |
} | |
else if (expr[[1]] != quote(`{`) && !any(vapply(expr[-1], | |
identical, quote(.), FUN.VALUE = logical(1))) && !any(vapply(expr[-1], | |
identical, quote(`!!!.`), FUN.VALUE = logical(1)))) { | |
expr <- as.call(c(expr[[1]], quote(.), as.list(expr[-1]))) | |
} | |
res <- eval(expr, envir = list(. = lhs), enclos = parent.frame()) | |
res | |
} | |
assign("%>%", pipe, envir = parent.frame()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment