diff --git a/R/layer.R b/R/layer.R index d4396aeb4e..179f519441 100644 --- a/R/layer.R +++ b/R/layer.R @@ -974,7 +974,8 @@ normalise_label <- function(label) { if (obj_is_list(label)) { # Ensure that each element in the list has length 1 label[lengths(label) == 0] <- "" - label <- lapply(label, `[`, 1) + truncate <- !vapply(label, is.call, logical(1)) # Don't mess with call/formula + label[truncate] <- lapply(label[truncate], `[`, 1) } if (is.expression(label)) { # Classed expressions, when converted to lists, retain their class. diff --git a/R/position-.R b/R/position-.R index 845b095862..4f3008c725 100644 --- a/R/position-.R +++ b/R/position-.R @@ -102,6 +102,10 @@ Position <- ggproto( #' A data frame with completed layer data use_defaults = function(self, data, params = list()) { + if (empty(data)) { + return(data) + } + aes <- self$aesthetics() defaults <- self$default_aes @@ -113,6 +117,13 @@ Position <- ggproto( return(data) } + empty_aes <- names(params)[lengths(params) == 0] + if (length(empty_aes) > 0) { + # The Geom$use_defaults method will already warn about this, we just need + # to ignore this here. + params <- params[setdiff(names(params), empty_aes)] + } + new <- compact(lapply(defaults, eval_tidy, data = data)) new[names(params)] <- params check_aesthetics(new, nrow(data)) diff --git a/R/stat-align.R b/R/stat-align.R index 7278773cf3..c0807382c7 100644 --- a/R/stat-align.R +++ b/R/stat-align.R @@ -77,7 +77,7 @@ StatAlign <- ggproto( finish_layer = function(data, params) { # Silently remove out-of-bounds padding vertices - var <- flipped_names(params$flipped_aes)$x + var <- flipped_names(params$flipped_aes %||% FALSE)$x remove <- is.na(data[[var]]) & (data$align_padding %||% FALSE) vec_slice(data, !remove) }