Skip to content

Commit 984bf51

Browse files
authored
Handle label functions that return character(0) (#3740)
1 parent 2303fd4 commit 984bf51

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

R/guides-axis.r

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ guide_train.axis <- function(guide, scale, aesthetic = NULL) {
8585
ticks$.value <- breaks
8686
ticks$.label <- scale$get_labels(breaks)
8787

88-
if (is.list(ticks$.label)) {
89-
if (any(sapply(ticks$.label, is.language))) {
90-
ticks$.label <- do.call(expression, ticks$.label)
91-
} else {
92-
ticks$.label <- unlist(ticks$.label)
93-
}
94-
}
95-
9688
guide$key <- ticks[is.finite(ticks[[aesthetic]]), ]
9789
}
9890

R/scale-.r

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,18 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
687687
if (length(labels) != length(breaks)) {
688688
abort("Breaks and labels are different lengths")
689689
}
690+
if (is.list(labels)) {
691+
# Guard against list with empty elements
692+
labels[vapply(labels, length, integer(1)) == 0] <- ""
693+
# Make sure each element is scalar
694+
labels <- lapply(labels, `[`, 1)
695+
696+
if (any(vapply(labels, is.language, logical(1)))) {
697+
labels <- do.call(expression, labels)
698+
} else {
699+
labels <- unlist(labels)
700+
}
701+
}
690702

691703
labels
692704
},

0 commit comments

Comments
 (0)