Skip to content

Commit

Permalink
repair names that might have become lost
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Jan 22, 2025
1 parent 97edd62 commit c3dea03
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion R/plot-construction.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,20 @@ ggplot_add.by <- function(object, plot, object_name) {

#' @export
ggplot_add.Layer <- function(object, plot, object_name) {
layers_names <- new_layer_names(object, names(plot$layers))
layers_names <- new_layer_names(object, names2(plot$layers))
plot$layers <- append(plot$layers, object)
names(plot$layers) <- layers_names
plot
}

new_layer_names <- function(layer, existing) {

empty <- !nzchar(existing)
if (any(empty)) {
existing[empty] <- "unknown"
existing <- vec_as_names(existing, repair = "unique", quiet = TRUE)

Check warning on line 209 in R/plot-construction.R

View check run for this annotation

Codecov / codecov/patch

R/plot-construction.R#L208-L209

Added lines #L208 - L209 were not covered by tests
}

new_name <- layer$name
if (is.null(new_name)) {
# Construct a name from the layer's call
Expand Down

0 comments on commit c3dea03

Please sign in to comment.