Skip to content

Commit fb012d8

Browse files
committed
Zero length vs NULL can actually be meaningful so just safe guard against error
1 parent 2811e61 commit fb012d8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

R/ggplotly.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,8 @@ gg2list <- function(p, width = NULL, height = NULL,
746746

747747
# https://github.com/tidyverse/ggplot2/pull/3566#issuecomment-565085809
748748
hasTickText <- !(is.na(ticktext) | is.na(tickvals))
749-
ticktext <- as.character(unlist(ticktext[hasTickText])) %||% NULL
750-
tickvals <- as.numeric(unlist(tickvals[hasTickText])) %||% NULL
749+
ticktext <- as.character(unlist(ticktext[hasTickText]))
750+
tickvals <- as.numeric(unlist(tickvals[hasTickText]))
751751

752752
axisObj <- list(
753753
# TODO: log type?
@@ -1441,7 +1441,9 @@ gdef2trace <- function(gdef, theme, gglayout) {
14411441
}
14421442

14431443
vals <- lapply(gglayout[c("xaxis", "yaxis")], function(ax) {
1444-
if (identical(ax$tickmode, "auto")) ax$ticktext else ax$tickvals
1444+
res <- if (identical(ax$tickmode, "auto")) ax$ticktext else ax$tickvals
1445+
# if zero-length, return NULL to avoid subscript oob errors
1446+
res %||% NULL
14451447
})
14461448

14471449
list(

0 commit comments

Comments
 (0)