From d41a675b5c63469bcef75736d748cb00db9ac992 Mon Sep 17 00:00:00 2001 From: Wim Date: Tue, 15 Oct 2019 20:27:13 +0200 Subject: [PATCH 1/2] Do not create structure with NULL to remove warnings --- R/plotly_build.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/plotly_build.R b/R/plotly_build.R index 2cf5de65aa..abaa8e5b61 100644 --- a/R/plotly_build.R +++ b/R/plotly_build.R @@ -280,10 +280,12 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) { ) for (i in x$.plotlyVariableMapping) { # try to reduce the amount of data we have to send for non-positional scales - x[[i]] <- structure( - if (i %in% npscales()) uniq(d[[i]]) else d[[i]], - class = oldClass(x[[i]]) - ) + entry <- if (i %in% npscales()) uniq(d[[i]]) else d[[i]] + if (is.null(entry)) { + x[[i]] <- NULL + } else { + x[[i]] <- structure(entry, class = oldClass(x[[i]])) + } } x }) From 599b851d4adb0c427d52c9f0b67d1cb3ba45cecb Mon Sep 17 00:00:00 2001 From: Wim Date: Sat, 19 Oct 2019 10:36:25 +0200 Subject: [PATCH 2/2] Add test to prove #1299 fix --- tests/testthat/test-ggplot-lines.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/testthat/test-ggplot-lines.R b/tests/testthat/test-ggplot-lines.R index 08095c8694..e0d437985a 100644 --- a/tests/testthat/test-ggplot-lines.R +++ b/tests/testthat/test-ggplot-lines.R @@ -120,3 +120,10 @@ test_that("geom_linerange() without a y aesthetic translates to a path", { ) }) + +test_that("NA values do not cause a lot of warnings when ploting (#1299)", { + df <- data.frame(x=1:2, y=NA) + p <- plot_ly(df, x=~x, y=~y) + expect_warning(plotly_build(p), "Ignoring") + expect_failure(expect_warning(plotly_build(p), "structure")) +})