Last active
November 5, 2020 21:25
-
-
Save eliocamp/91ea0c322b5062f9945c6f12a4f1592e to your computer and use it in GitHub Desktop.
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
ditto <- function(expr) { | |
plus_fun <- function(e1, e2) { | |
if (is.list(e1)) { | |
c(e1, list(e2)) | |
} else { | |
list(e1, e2) | |
} | |
} | |
geom_list <- eval(substitute(expr), envir = list("+.gg" = plus_fun), enclos = parent.frame()) | |
e1 <- geom_list[[1]] | |
for (i in seq_along(geom_list)[-1]) { | |
e2 <- geom_list[[i]] | |
geom_list[[i]]$geom_params <- stomp(e2$geom_params, | |
e1$geom_params) | |
geom_list[[i]]$aes_params <- stomp(e2$aes_params, | |
e1$aes_params) | |
geom_list[[i]]$stat_params <- stomp(e2$stat_params, | |
e1$stat_params) | |
geom_list[[i]]$mapping <- e1$mapping | |
} | |
geom_list | |
} | |
stomp <- function(original, new) { | |
names <- names(new) | |
for (name in names) { | |
original[[name]] <- new[[name]] | |
} | |
original | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment