Skip to content

Commit 66d6ee4

Browse files
authored
repair names that might have become lost (#6298)
1 parent 8ef9c6e commit 66d6ee4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

R/plot-construction.R

+8-1
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,20 @@ ggplot_add.by <- function(object, plot, object_name) {
195195

196196
#' @export
197197
ggplot_add.Layer <- function(object, plot, object_name) {
198-
layers_names <- new_layer_names(object, names(plot$layers))
198+
layers_names <- new_layer_names(object, names2(plot$layers))
199199
plot$layers <- append(plot$layers, object)
200200
names(plot$layers) <- layers_names
201201
plot
202202
}
203203

204204
new_layer_names <- function(layer, existing) {
205+
206+
empty <- !nzchar(existing)
207+
if (any(empty)) {
208+
existing[empty] <- "unknown"
209+
existing <- vec_as_names(existing, repair = "unique", quiet = TRUE)
210+
}
211+
205212
new_name <- layer$name
206213
if (is.null(new_name)) {
207214
# Construct a name from the layer's call

0 commit comments

Comments
 (0)