Skip to content

Commit 3f6e315

Browse files
committed
allow empty annotations. fixes #3317
1 parent 3b69172 commit 3f6e315

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

R/annotation.r

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ annotate <- function(geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL,
4646

4747
# Check that all aesthetic have compatible lengths
4848
lengths <- vapply(aesthetics, length, integer(1))
49-
unequal <- length(unique(setdiff(lengths, 1L))) > 1L
49+
n <- unique(setdiff(lengths, 1L))
50+
unequal <- length(n) > 1L
5051
if (unequal) {
5152
bad <- lengths != 1L
5253
details <- paste(names(aesthetics)[bad], " (", lengths[bad], ")",
5354
sep = "", collapse = ", ")
5455
stop("Unequal parameter lengths: ", details, call. = FALSE)
5556
}
5657

57-
data <- new_data_frame(position, n = max(lengths))
58+
data <- new_data_frame(position, n = n)
5859
layer(
5960
geom = geom,
6061
params = list(

R/performance.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ new_data_frame <- function(x = list(), n = NULL) {
44
if (length(x) != 0 && is.null(names(x))) stop("Elements must be named", call. = FALSE)
55
lengths <- vapply(x, length, integer(1))
66
if (is.null(n)) {
7-
n <- if (length(x) == 0) 0 else max(lengths)
7+
n <- if (length(x) == 0 || min(lengths) == 0) 0 else max(lengths)
88
}
99
for (i in seq_along(x)) {
1010
if (lengths[i] == n) next
@@ -32,7 +32,7 @@ split_matrix <- function(x, col_names = colnames(x)) {
3232
if (!is.null(col_names)) names(x) <- col_names
3333
x
3434
}
35-
35+
3636
mat_2_df <- function(x, col_names = colnames(x)) {
3737
new_data_frame(split_matrix(x, col_names))
3838
}

0 commit comments

Comments
 (0)