Skip to content

Commit ba1740a

Browse files
committed
use helper
1 parent 5a7b9ed commit ba1740a

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

R/geom-.R

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,10 @@ Geom <- ggproto("Geom",
157157
# This order means that they will have access to all default aesthetics
158158
if (length(modifiers) != 0) {
159159
# Set up evaluation environment
160-
env <- child_env(baseenv(), after_scale = after_scale)
161-
# Mask stage with stage_scaled so it returns the correct expression
162-
stage_mask <- child_env(emptyenv(), stage = stage_scaled)
163-
mask <- new_data_mask(as_environment(data, stage_mask), stage_mask)
164-
mask$.data <- as_data_pronoun(mask)
165-
modified_aes <- lapply(substitute_aes(modifiers), eval_tidy, mask, env)
160+
modified_aes <- eval_aesthetics(
161+
substitute_aes(modifiers), data,
162+
mask = list(stage = stage_scaled)
163+
)
166164

167165
# Check that all output are valid data
168166
nondata_modified <- check_nondata_cols(modified_aes)
@@ -177,11 +175,9 @@ Geom <- ggproto("Geom",
177175
))
178176
}
179177

180-
names(modified_aes) <- names(rename_aes(modifiers))
181-
182178
modified_aes <- cleanup_mismatched_data(modified_aes, nrow(data), "after_scale")
183179

184-
modified_aes <- data_frame0(!!!compact(modified_aes))
180+
modified_aes <- data_frame0(!!!modified_aes)
185181

186182
data <- cunion(modified_aes, data)
187183
}

R/layer.R

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
#' `NA`, the default, includes if any aesthetics are mapped.
5959
#' `FALSE` never includes, and `TRUE` always includes.
6060
#' It can also be a named logical vector to finely select the aesthetics to
61-
#' display. To include legend keys for all levels, even
62-
#' when no data exists, use `TRUE`. If `NA`, all levels are shown in legend,
61+
#' display. To include legend keys for all levels, even
62+
#' when no data exists, use `TRUE`. If `NA`, all levels are shown in legend,
6363
#' but unobserved levels are omitted.
6464
#' @param inherit.aes If `FALSE`, overrides the default aesthetics,
6565
#' rather than combining with them. This is most useful for helper functions
@@ -303,10 +303,7 @@ Layer <- ggproto("Layer", NULL,
303303
}
304304

305305
# Evaluate aesthetics
306-
env <- child_env(baseenv(), stage = stage)
307-
evaled <- lapply(aesthetics, eval_tidy, data = data, env = env)
308-
evaled <- compact(evaled)
309-
306+
evaled <- eval_aesthetics(aesthetics, data)
310307
plot$scales$add_defaults(evaled, plot$plot_env)
311308

312309
# Check for discouraged usage in mapping
@@ -386,14 +383,10 @@ Layer <- ggproto("Layer", NULL,
386383
data_orig <- plot$scales$backtransform_df(data)
387384

388385
# Add map stat output to aesthetics
389-
env <- child_env(baseenv(), stat = stat, after_stat = after_stat)
390-
stage_mask <- child_env(emptyenv(), stage = stage_calculated)
391-
mask <- new_data_mask(as_environment(data_orig, stage_mask), stage_mask)
392-
mask$.data <- as_data_pronoun(mask)
393-
394-
new <- substitute_aes(new)
395-
stat_data <- lapply(new, eval_tidy, mask, env)
396-
386+
stat_data <- eval_aesthetics(
387+
substitute_aes(new), data_orig,
388+
mask = list(stage = stage_calculated)
389+
)
397390
# Check that all columns in aesthetic stats are valid data
398391
nondata_stat_cols <- check_nondata_cols(stat_data)
399392
if (length(nondata_stat_cols) > 0) {
@@ -407,8 +400,7 @@ Layer <- ggproto("Layer", NULL,
407400
))
408401
}
409402

410-
names(stat_data) <- names(new)
411-
stat_data <- data_frame0(!!!compact(stat_data))
403+
stat_data <- data_frame0(!!!stat_data)
412404

413405
# Add any new scales, if needed
414406
plot$scales$add_defaults(stat_data, plot$plot_env)

0 commit comments

Comments
 (0)