library(ggplot2)
library(rlang)
ggplot <- function(...) {
f <- function(...) list(clone = f)
structure(
list(
call = sys.call()
),
class = "gg"
)
}
`+.gg` <- function(e1, e2) {
e2 <- enexpr(e2)
e1$call <- expr(!!e1$call + !!e2)
e1
}
p <- ggplot(mpg, aes(cty)) +
geom_bar()
p
#> $call
#> ggplot(mpg, aes(cty)) + geom_bar()
#>
#> attr(,"class")
#> [1] "gg"
eval_bare(p$call, env(ggplot = ggplot2::ggplot, `+.gg` = ggplot2:::`+.gg`))
Created on 2020-01-31 by the reprex package (v0.3.0)