From b554bddf621c251fad31a4a0058a3882bf5bed6d Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Thu, 21 Jul 2016 10:37:13 -0500 Subject: [PATCH 1/2] make sure index is a character before performing lookup, fixes #650 --- R/plotly_build.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/plotly_build.R b/R/plotly_build.R index b4fdbc5539..10c5bcc9c2 100644 --- a/R/plotly_build.R +++ b/R/plotly_build.R @@ -533,7 +533,7 @@ map_symbol <- function(traces) { palette <- setNames(symbols[seq_len(N)], unique(symbol)) for (i in which(nSymbols > 0)) { s <- symbolList[[i]] - symbols <- pch2symbol(if (inherits(s, "AsIs")) s else as.character(palette[s])) + symbols <- pch2symbol(if (inherits(s, "AsIs")) s else as.character(palette[as.character(s)])) illegalSymbols <- setdiff(symbols, validSymbols) if (length(illegalSymbols)) { warning( @@ -581,7 +581,7 @@ map_linetype <- function(traces) { palette <- setNames(linetypes[seq_len(N)], unique(linetype)) for (i in which(nLinetypes > 0)) { l <- linetypeList[[i]] - dashes <- lty2dash(if (inherits(l, "AsIs")) l else as.character(palette[l])) + dashes <- lty2dash(if (inherits(l, "AsIs")) l else as.character(palette[as.character(l)])) illegalLinetypes <- setdiff(dashes, validLinetypes) if (length(illegalLinetypes)) { warning( From 679f33fb2e49ba7a0212266107c5491aa54f6766 Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Mon, 25 Jul 2016 11:53:01 -0500 Subject: [PATCH 2/2] add test --- tests/testthat/test-plotly-symbol.R | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/testthat/test-plotly-symbol.R b/tests/testthat/test-plotly-symbol.R index 3ad5b8908d..5c9e5cb0d4 100644 --- a/tests/testthat/test-plotly-symbol.R +++ b/tests/testthat/test-plotly-symbol.R @@ -37,3 +37,12 @@ test_that("Warn about invalid symbol codes", { p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, symbol = I("DNE")) expect_warning(plotly_build(p), "DNE") }) + +test_that("Formula resulting in logical vector works", { + s <- c("triangle-up", "circle-open") + p <- plot_ly(x = 1:10, y = 1:10, symbol = ~1:10 > 5, symbols = s) + l <- expect_traces(p, 2, "logical") + markers <- lapply(l$data, "[[", "marker") + syms <- unlist(lapply(markers, "[[", "symbol")) + expect_identical(syms, s) +})