@@ -126,14 +126,14 @@ Geom <- ggproto("Geom",
126126 # Take care of subclasses setting the wrong default when inheriting from
127127 # a geom with rename_size = TRUE
128128 if (self $ rename_size && is.null(default_aes $ linewidth )) {
129- deprecate_soft0 (" 3.4.0" , I(" Using the `size` aesthetic in this geom" ), I(" `linewidth` in the `default_aes` field and elsewhere" ))
129+ deprecate_warn0 (" 3.4.0" , I(" Using the `size` aesthetic in this geom" ), I(" `linewidth` in the `default_aes` field and elsewhere" ))
130130 default_aes $ linewidth <- default_aes $ size
131131 }
132132
133133 # Fill in missing aesthetics with their defaults
134134 missing_aes <- setdiff(names(default_aes ), names(data ))
135135 default_aes <- default_aes [missing_aes ]
136- themed_defaults <- eval_from_theme(default_aes , theme )
136+ themed_defaults <- eval_from_theme(default_aes , theme , class( self ) )
137137 default_aes [names(themed_defaults )] <- themed_defaults
138138
139139 # Mark staged/scaled defaults as modifier (#6135)
@@ -163,10 +163,15 @@ Geom <- ggproto("Geom",
163163 # If any after_scale mappings are detected they will be resolved here
164164 # This order means that they will have access to all default aesthetics
165165 if (length(modifiers ) != 0 ) {
166- # Set up evaluation environment
167- modified_aes <- eval_aesthetics(
168- substitute_aes(modifiers ), data ,
169- mask = list (stage = stage_scaled )
166+ modified_aes <- try_fetch(
167+ eval_aesthetics(
168+ substitute_aes(modifiers ), data ,
169+ mask = list (stage = stage_scaled )
170+ ),
171+ error = function (cnd ) {
172+ cli :: cli_warn(" Unable to apply staged modifications." , parent = cnd )
173+ data_frame0()
174+ }
170175 )
171176
172177 # Check that all output are valid data
@@ -177,10 +182,7 @@ Geom <- ggproto("Geom",
177182 )
178183
179184 modified_aes <- cleanup_mismatched_data(modified_aes , nrow(data ), " after_scale" )
180-
181- modified_aes <- data_frame0(!!! modified_aes )
182-
183- data <- data_frame0(!!! defaults(modified_aes , data ))
185+ data [names(modified_aes )] <- modified_aes
184186 }
185187
186188 # Override mappings with params
@@ -237,13 +239,33 @@ Geom <- ggproto("Geom",
237239# ' @rdname is_tests
238240is.geom <- function (x ) inherits(x , " Geom" )
239241
240- eval_from_theme <- function (aesthetics , theme ) {
242+ eval_from_theme <- function (aesthetics , theme , class = NULL ) {
241243 themed <- is_themed_aes(aesthetics )
242244 if (! any(themed )) {
243245 return (aesthetics )
244246 }
245- settings <- calc_element(" geom" , theme ) %|| % .default_geom_element
246- lapply(aesthetics [themed ], eval_tidy , data = settings )
247+
248+ element <- calc_element(" geom" , theme ) %|| % .default_geom_element
249+ class <- setdiff(class , c(" Geom" , " ggproto" , " gg" ))
250+
251+ if (length(class ) > 0 ) {
252+
253+ # CamelCase to dot.case
254+ class <- gsub(" ([A-Za-z])([A-Z])([a-z])" , " \\ 1.\\ 2\\ 3" , class )
255+ class <- gsub(" ([a-z])([A-Z])" , " \\ 1.\\ 2" , class )
256+ class <- to_lower_ascii(class )
257+
258+ class <- class [class %in% names(theme )]
259+
260+ # Inherit up to parent geom class
261+ if (length(class ) > 0 ) {
262+ for (cls in rev(class )) {
263+ element <- combine_elements(theme [[cls ]], element )
264+ }
265+ }
266+ }
267+
268+ lapply(aesthetics [themed ], eval_tidy , data = element )
247269}
248270
249271# ' Graphical units
@@ -279,7 +301,7 @@ check_aesthetics <- function(x, n) {
279301
280302fix_linewidth <- function (data , name ) {
281303 if (is.null(data $ linewidth ) && ! is.null(data $ size )) {
282- deprecate_soft0 (" 3.4.0" , I(paste0(" Using the `size` aesthetic with " , name )), I(" the `linewidth` aesthetic" ))
304+ deprecate_warn0 (" 3.4.0" , I(paste0(" Using the `size` aesthetic with " , name )), I(" the `linewidth` aesthetic" ))
283305 data $ linewidth <- data $ size
284306 }
285307 data
0 commit comments