Skip to content

Commit f9e3855

Browse files
Evaluate
1 parent 192dfba commit f9e3855

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

R/aes-evaluation.r

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,18 @@ strip_stage <- function(expr) {
179179
if (is_call(uq_expr, c("after_stat", "after_scale"))) {
180180
uq_expr[[2]]
181181
} else if (is_call(uq_expr, "stage")) {
182-
# Prefer stat mapping if present
183-
if (!is.null(uq_expr$after_stat))
184-
return(uq_expr$after_stat)
182+
# Since the argument matching is a bit difficult to get done right,
183+
# let's actually evaluate it.
184+
sandbox_env <- env(stage = function(start, after_stat, after_scale) {
185+
expr <- enexprs(start = start, after_stat = after_stat)
186+
if (!is_missing(expr$after_stat)) {
187+
expr$after_stat
188+
} else {
189+
expr$start
190+
}
191+
})
185192

186-
# otherwise original mapping (fallback to scale mapping)
187-
if (!is.null(uq_expr$start))
188-
return(uq_expr$start)
189-
190-
# The case when after_stat is positionally provided
191-
if (is.null(uq_expr$after_scale) && length(uq_expr) >= 3)
192-
return(uq_expr[[3]])
193-
194-
# The case when stage() has only one unnamed arg
195-
uq_expr[[2]]
193+
eval_bare(uq_expr, sandbox_env)
196194
} else {
197195
expr
198196
}

0 commit comments

Comments
 (0)